Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Should ComponentDatas be designed to minimize excess unused data when filtered?

Discussion in 'Data Oriented Technology Stack' started by Mr-Mechanical, Jan 18, 2019.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    191
    Here's a random example that illustrates my point: if you have a ComponentData that has a float3 field but you only need the x-coordinate of the float3 in some systems, would it make sense to have 3 separate float x, float y, float z ComponentDatas so that you can filter for just the x coordinate ComponentData to save some CPU cache usage? I'd like to know if this is more efficent before I start dividing ComponentDatas. Thanks. Any feedback is always helpful.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,814
    Sounds like over optimization.

    If the data makes sense together, keep it together imo.

    I very much doubt any potential performance gains would warrant the mess.
     
  3. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    191
    I agree that chopping up a float3 wouldn't be pretty. But do you think it would be worth it if you had the same situation but with a larger component data instead of float3 ? Thank you for the input.
     
  4. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    331
    From your first post I would say you understand the problem. Yes, the bigger ComponentData is, the less of them will fit to the cache.

    The example you posted looks indeed extreme, but I can imagine that it could give some performance gain in some scenarios.

    But nobody can answer this question for you. Do some tests and you will see if it is worth or not.
     
    Mr-Mechanical and orionburcham like this.
  5. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    491
    Fido789’s response is right on the money.

    You understand the problem. However, how much benefit you’d get from splitting a float3 into separate components depends on how your systems read and write that data. If you almost always access all three of those new components together, then you won’t gain much benefit.
     
    Mr-Mechanical likes this.