Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Does Data Oriented Design provide a performance benefit with Unity script?

Discussion in 'Scripting' started by MarkMizuguchi, Jul 24, 2012.

  1. MarkMizuguchi

    MarkMizuguchi

    Joined:
    Jul 11, 2012
    Posts:
    2
    I come from a C++ game coding on consoles background where data oriented design is paramount to writing games that perform efficiently.

    The Unity API and the way it handles GameObject updates is set-up in a very object oriented manner counter to data oriented design. I can see ways to structure my Unity script in a more data oriented way such as having GameObject components queue requests in arrays for batch processing. This appears to run counter to how Unity script is intended to be used though. Before I go down this road, has anyone had any experience with a data oriented design approach in Unity? Was there a tangible performance benefit? Does the underlying API and virtual machine negate any attempts to make things more cache coherent?

    For more concrete examples:
    • Is there a performance benefit to handling all Physics.Raycast() calls in a tight loop storing the results in an array rather than having the calls sprinkled throughout Update() calls of various components of various GameObjects?
    • Same question as above for lower level collision calls like CapsuleCollider.ClosestPointOnBounds().
    • Do the memory accesses required by the virtual machine cause a flush of the data and instruction caches even on the tightest loops?
    As a final question, are there drastic differences between platforms such as ARM/iOS and Intel/PC (i.e. useful for one platform but not the other)?
     
    vexe likes this.
  2. znoey

    znoey

    Joined:
    Oct 27, 2011
    Posts:
    174
    I'd be interested in finding these things out as well. I'm not real big on dod and none of my apps need excruciating performance, but i would love to know more about this. The links above were a great read already.
     
  3. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    Well, we know for sure that the more Update calls made, the more performance is degraded because there's overhead involved in calling a method, and keep in mind not all methods are made equal (virtual, static, interface, etc...) so some take longer to dispatch than others (although we're talking miniscule overhead here); whether the degredation is negligible or not depends entirely on the app, so profiling is necessary.

    .
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    Definitely worth some testing, I think.

    My gut feel says yes, it'd give performance benefits, but I've never needed to care about script performance to that degree (the vast majority of my code is latent) and who knows how the underlying components of Unity (Mono/native interop springs to mind) would impact the gains?
     
  5. loesch94

    loesch94

    Joined:
    Dec 13, 2014
    Posts:
    1
    Did this ever come to a resolution? I have only just started with Unity and I am curious if this road is one I should be looking into. Regardless of whether it has performance benefits, do people recommend getting experience with DOD?
     
  6. erlendsh

    erlendsh

    Joined:
    Jul 2, 2015
    Posts:
    3
  7. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
  8. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641