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

Thanks for Burst, got a 40x improvement in my Asset

Discussion in 'Burst' started by SpookyCat, Feb 23, 2021.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    What great systems Burst and Jobs are, I have converted my Mesh Deformation system over and generally see between 40 to 50 times less CPU usage for the same scene. Took a bit of fiddling with but have to say it is a really nice easy to use system, I look forward to seeing what else you add to it. Below is a little video showing the before and after, pretty sure I can squeeze some more performance out of it but a good start.
     
    Sab_Rango, PutridEx, neekoh and 17 others like this.
  2. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,117
    Are you also using the direct access to mesh data API as well? I assume the answer is yes and a big chunk of the 40x is from that right?
     
  3. jasons-novaleaf

    jasons-novaleaf

    Joined:
    Sep 13, 2012
    Posts:
    181
    Could you share some examples of poor-performance, and how you converted them?
     
  4. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Actually not using the Mesh Data Api at all, so the Speed up is purely from converting the Maths code for each deformer to a Burst Compiled Job, also having a custom Job for calculating the Normal data as the standard built in Unity RecalcNormals does not preserve smoothing groups and UV seams etc. I did look at the Mesh Data Api but for my use it doesn't really help much from what I could see, though would be more than happy to be told I am wrong there :)
     
    NotaNaN and JesOb like this.
  5. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    As I said just above most of the speed up comes from custom Burst Compiled Jobs and inside those jobs making use of Unity.Mathematics methods over the normal Mathf etc. Some of the biggest gains I got was also from converting my Spline Interpolator to Burst and jobs as well as a custom Burst/Jobs version of AnimationCurve. When I started I was expecting a long battle trying to get a respectable speed up from the old code but everything just seemed to work out of the box, and was refeshingly simple. Only slightly painful part was the managing of NativeArrays especially as the system runs in both the Editor and Play mode and trying to stop 'leaks' which weren't actually leaks when Unity recompiled running Editor code and switching in and out of Play mode.
     
  6. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,117
    Well depends on how you are doing your modifications, If you process one vertex at a time then it will not make any difference but if you copy your mesh data to native arrays for processing them in a job and change positions and then copy the array to the Vector3s of the vertext data then for sure it will help by doing a much faster copy but I might be wrong.

    Also processing the arrays in jobs gives you the benefit that you can use SIMD in places which you cannot do it for a single vertext by processing multiple vertices at a time.

    I'm saying this all without knowing how you are handling it. I vaguely remember when evaluating MegaFiers you had a way of writing custom modifiers and I assume you use the same way yourself too but don't remember how exactly it was
     
  7. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    The data is in NativeArrays and I use the Parrallel For to process it.
     
  8. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,117
    Ok if you don't copy the arrays, you are using the most performant way.
     
  9. neekoh

    neekoh

    Joined:
    Nov 16, 2012
    Posts:
    9
    Wrt. handling managed and NativeArrays (I’m not sure there’s need in this case), please have a look at Stella3D’s SharedArray. I’ve found this a great and easy to use mechanism to share data between both. Even comes with type aliasing, so one can use e.g. Vector3 for managed and float3 for native.
    https://github.com/stella3d/SharedArray
     
    Ghat-Smith likes this.
  10. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    The nice thing about dots is exactly this. For many, they don't wanna switch yet. But the asset creators can utilities it for a large perf gain that is almost invisible from the customer. It's really cool.