Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved How to analyze and optimize converted SubScene size?

Discussion in 'DOTS Dev Blitz Day 2023 - Q&A' started by WildMaN, Aug 24, 2023.

  1. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    127
    Hi,

    My game has hundreds of levels (subscenes) with tens of thousands of entities each. That occupies a pretty sizeable storage space, an issue for a mobile game. Surprisingly, the converted subscene size is roughly 4x the size of [entities count] X [bytes in the archetypes].

    Is there a way besides brute-forcing with the hex editor to examine, analyze, and optimize the converted subscene size?
     
  2. topher_r

    topher_r

    Unity Technologies

    Joined:
    Jun 14, 2019
    Posts:
    36
    What are you counting? SubScenes include Unity assets in some of the files (e.g. Textures, Materials etc). In fact, a 'SubScene' is many different files.
     
  3. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    127
    My subscenes are pure collections of physics entities with shared colliders, no meshes, renderers, textures, materials, etc. I'm referring to "assets/SubScenes" folder in the final build with <GUID>.0.entities files in it - those occupy roughly 4 times more space than entities in those scenes should, according to my math.
     
  4. topher_r

    topher_r

    Unity Technologies

    Joined:
    Jun 14, 2019
    Posts:
    36
    Most likely they contain Blob assets of collider information, have you accounted for the size of those? They won't be deduplicated.

    To answer your initial question, there is no tool to break down the contents of an Entity Scene externally, but everything in an Entity Scene is loaded/accessible when it gets loaded. So the best advice I can give is to load the scene into a world and review the data that gets loaded into it.
     
  5. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    127
    That would be my guess as well, but the physics collider blob and shared colliders approach aren’t well documented, unfortunately. I definitely didn’t set “unique collider” authoring flag, but does it mean that all cubes will share a single cube collider, all pyramids their own singleton etc - I don’t know. Is there a way to check how many colliders get baked into the subsceen?
     
  6. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    Unfortunately there is currently no easy way to identify the exact number of collider blobs that are created for a given number of
    PhysicsCollider
    components (i.e., conceptual rigid bodies).

    By default, all identical colliders (identical being defined as same collider type, same geometric properties, e.g., box size or sphere radius, and same collision filter and material settings) are shared unless they are forced to be "unique", as you pointed out above.
    Currently (as of version 1.0.14), the only way to ensure "force unique" colliders is through the corresponding property in the custom Physics Shape authoring components (see the corresponding section in the documentation).

    If you need to know the exact amount of memory occupied by all collider blobs combined, you could create a baking system that runs after all colliders have been baked using
    [UpdateAfter(typeof(EndColliderBakingSystem))]
    and then process all
    PhysicsCollider
    components and insert all unique collider blobs (
    PhysicsCollider.Value
    ) into a hash map using either their hash code (
    PhysicsCollider.Value.GetHashCode()
    ) or their actual pointer address
    PhysicsCollider.Value.GetUnsafePtr()
    to identify all unique ones.
    After that, you can sum up the memory occupied by the colliders in the hash map using the collider's memory size property (
    PhysicsCollider.Value.Value.MemorySize
    ), which returns the collider's memory size in number of bytes.
     
  7. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    127
    I did a simple test and it definitely shows something weird.
    https://forum.unity.com/threads/researching-the-duplication-of-colliders.1484220/

    I have thousands of entities of only a dozen or so types, so I'd expect a dozen or so unique colliders. But there are over 4000 unique blobs, many with just 1 or 2 references.

    Entities are authored from prefabs, so for sure their authoring values are identical in type, sizes, filters, and materials.
     
  8. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    I just answered in your other thread.