Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback ETA of various performance optimization

Discussion in 'NetCode for ECS' started by optimise, Oct 4, 2023.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    Currently at latest 1.1.0-exp. release, I still have the following performance issues profile from my project at android device i.e. Mi 9T Pro (Snagdragon 855) and would like to know when official is planning to address each item that it will fix at 1.1, 1.2 or later?

    1) Remove GhostInputSystemGroup system stalling caused by GhostUpdateSystem:UpdateJob. Expected to reduce around 1ms.
    upload_2023-10-5_0-57-55.png


    2) Batch build physics world system to update only once in 1 frame instead of multiple times. Expected to reduce around 0.6ms+.
    upload_2023-10-5_1-0-5.png


    3) Remove SolveAndIntegrateSystem stalling caused by BroadphaseSystem and also remove malloc. Expected to reduce around 0.8ms+.
    upload_2023-10-5_1-2-7.png

    4) Remove GhostCollectionSystem stalling caused by complete jobs I guess. Expected to reduce around 0.17ms+.

    upload_2023-10-5_1-5-23.png

    5) Remove PredictedSimulationSystemGroup stalling caused by complete job. Expected to reduce around 0.22ms+. See https://github.com/tertle/com.unity.entities/commit/3c81cc6e43780e1c55ba93b5cc6a0c285003cad5

    upload_2023-10-5_1-8-5.png
     
    Last edited: Oct 4, 2023
    mgear likes this.
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    Probably (potentially) maybe 1.2 or later.
    Fixing the stall for the ghost input system is kinda little hard to do (because of the job dependencies in updating the OwnerIsLocal component). But, if you are willing to accept the possibility that the flag is outdated of one frame (when it become true or false) then we just opt to move the GhostInputSystem before the GhostUpdateSystem.

    The SolveAndIntegrateSystem stalling is almost on physics and the way they do the successive rescheduling of jobs for the step.

    Batching rebuild physics world is in there radar.

    GhostCollectinSystem and PredictedSimulationSystemGroup are in the radar.
     
    optimise likes this.
  3. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    I see. The flag is outdated of one frame (when it become true or false) are u refer to GhostOwnerIsLocal component that sometimes will stay enable/disable late 1 frame? But since I not sure how impactful for this changes, can implement it as define like GHOST_INPUT_SPEEDUP so I can switch back and forth to test it?
     
  4. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    Tertle fixed SolveAndIntegrateSystem and PredictedSimulationSystemGroup stalling but at editor there's netcode rpc error spamming needs to fix. Though player runtime build still working fine. I can try to submit a minimal repo if u want. Anyway I think official can merge this awesome improvement into official release together with error spamming fixed.
    https://forum.unity.com/threads/in-49838-1-0-11-massive-performance-spike.1467863/#post-9396932
     
  5. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    It did not solve them, it hacked them by removing waiting for job completetion and put the burden at the end of the command buffer. I already fixed the stalling in the PredictedSimulationSystemGroup too long ago (just the PR didn't land yet).
    The SolveAndIntegrateSystem can be fixed, but requires change in Physics, and does not solve the inner problem of that loop either.
     
    Occuros and optimise like this.
  6. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    Oh. I forget to tell u there are changes at netcode too. See https://github.com/tertle/com.unity.netcode. Are u doing similar changes?
     
  7. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    Something in line IIRC. I will double check its fork
     
  8. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    Is that GhostInputSystem, GhostCollectinSystem and PredictedSimulationSystemGroup performance optimization still planned at 1.2 or moved to 1.3?

    One more thing. I would like official to implement this to remove SystemState.BeforeOnUpdate.Complete() to stop sync points in fixed update to have the foundation for dots netcode and dots physics able to further improve the performance
    https://github.com/tertle/com.unity.entities/commit/5712bb75dfcf71a51b7fc9064b25f693d2f0a2fb
     
    Last edited: Dec 4, 2023
  9. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,732
    ^ don't use this in netcode unless you update the netcode rate managers and how they handle rewind allocator otherwise you will corrupt your memory silently
     
    Last edited: Dec 5, 2023
    tmonestudio and optimise like this.
  10. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    @CMarastoni Any new update for this?
     
  11. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    There will be not any removal for SystemState.BeforeOnUpdate.Complete(), because that would be a too big of a change at the moment. Can be discussed to be maybe an opt-in for certain systems but need to be discussed at Entities level. So I would say, ask that question to the other forum for better and larger visibility.
     
  12. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    Alright. How about optimization for BuildPhysicsWorld, GhostInputSystem and GhostCollectionSystem?
     
  13. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    BuildPhysicsWorld

    We have recently released (if not will be soon) a new sample that show how to customise the full physics loop to:
    - Build only once per prediction loop (or better, when thing change and require that update)
    - Disable/Enable certain systems only on the filnal step
    - Use immediate mode for both step and update

    It requires to create a custom BuildPhysicsWorld system at the moment for keeping physics pretty much untouched avoid changes in package, and let iterate on some ideas before making the default physics systems customisable without that need.

    GhostCollectionSystem

    We are planning some optimisation for this early this year. So stay tuned.

    GhostInputSystem
    For the GhostInputSystem, and in particular the fact you need to wait on the main thread until GhostUpdateSystem jobs has completed) there are two possibility we are looking at:
    1) Changing how the OnwerIsLocal is updated, so it can be done in parallel to other GhostUpdate jobs, effectively removing the wait.
    2) Move the GhostInputSystemGroup before the GhostUpdateSystem. However, this introduce two side-effect:
    a) The OwnerIsLocal is not up-to-date. What that mean: you sample and push the input for it even though it will be not controlled by the player if the owner is changed. That it is not a big of a problem, because that is also the case anyway due to the latency (you are sending input to a ghost you think you are in control, but the server has actually changed the owner).
    b) The ghost data is not up-to-date when you sample the input. That means, if you are getting some value from replicated components, it may be out of date. That can be a problem or not depending on the case.

    That would suggest this compromise solution does not look great. The most correct would be let user to choose where they want to sample the input (before and after) and letting them to eventually wait or not for any dependencies. That immediately suggests two groups are necessary: one before and one after the GhostUpdateSystem, that it is a little strange honestly.
     
    optimise likes this.
  14. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,106
    I guess 1) is the best solution but quite tedious to implement it?
     
  15. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    We are double checking it, it may be a little tedious yes. But doable.