Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feedback Multiple worlds seems very very slow?

Discussion in 'Physics for ECS' started by Jawsarn, Jan 18, 2023.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    259
    I did a small comparison between World, Filter and offsets for small isolated simulations. And it seems multiple world is a heavy punch on performance.

    My test was 32 simulations (see image) with 8 dynamics and ~70 statics (Sadly couldn't get the static to become one collider with instantiating from prefab), and the statics were not shared between worlds.

    World - 50 ms
    Filters - 9.85 ms
    Offsets - 9.61 ms

    upload_2023-1-18_15-9-16.png

    I don't like working with the limitation of 32 filters, so I guess I'll resort to offsets if nothing gets improved here.
     
  2. Scramblejams

    Scramblejams

    Joined:
    Oct 19, 2015
    Posts:
    7
    Apologies that I don't have anything to add to your query, but I'm trying to figure out how to do something similar -- instantiate multiple isolated physics worlds -- and you've gotten much further than I have. :) Do you have any example code or resources you could point me to? I've read through the docs I know of but have only found a bare outline of how to really do it.
     
  3. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    259
    https://github.com/Jawsarn/LocalSimulationTests
     
    PolarTron and Scramblejams like this.
  4. Selmar

    Selmar

    Joined:
    Sep 13, 2011
    Posts:
    61
    I had a similar issue just creating a lot of worlds with almost no data and I was not even updating them. This is probably not related to your case, since you need a lot of worlds to have this "problem", but just in case.

    I took a brief look at the profiler and it seems there is a post frame update that takes a lot of time in my case, it is executing a lot of memory profiler jobs on the main thread.
    Code (CSharp):
    1. Profiler.FrameMetadata
    2. UnityEngine.CoreModule.dll!::ExecuteJobFunction.Invoke() [Invoke]
    3. MemoryProfiler:MemoryProfilerJob
    4. UnityEngine.CoreModule.dll!::UpdateFunction.Invoke() [Invoke]
    5. UpdatePostFrame
    6.  
     
  5. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    705
    I have also seen multiple worlds (100+ of them) to be extremely slow, talking seconds per frame, even if they are empty.

    My approach before PhysicsWorldIndex and still now is patching CollisionFilter's IsCollisionEnabled to treat IndexGroup like it's a WorldIndex instead.

    Works pretty well, for sparse worlds like my space game that has many physics bubbles / worlds. Additional Performance can be gained by patching BVH to make certain assumptions about IndexGroups, or by making CollisionFilter Unions treat IndexGroups like bit fields, too.

    (Wow, I just realized that's a simple optimization I can make, currently I use hashes to generate groupindices, these occupy a lot of bits, but I only need maybe 2 or 3 bits (out of 16) tops, which gives me a big amount of room if I shuffle these appropriately into a Union-able IndexGroup.)
     
    Last edited: Mar 15, 2023