PolylinePath updates and GC

Avatar
  • updated
  • Answered

Hello,

First of all, thank you for this library, it is truly amazing and extremely versatile, and for sure something Unity was lacking.

I do have a question about best practices when it comes to updating a PolylinePath.
My scenario is very simple. I have a PolylinePath with about 100 points which I want to update every frame (position, color, and thickness).

I tried different techniques:

  • Every frame I ClearAllPoints and I use AddPoint
  • I initialize the PolylinePath in Awake/Start (with AddPoint) and then I use SetPoint every frame
  • I create a new PolylinePath every frame, add the points, draw, then dispose.

The problem that I am facing is that there is something allocating 227KB (GC.Alloc) every frame in my OnPreRenderer function, which triggers some GC spikes every ~200 frames where a GC.Collect takes between 80-110ms which results in a very visually noticeable stutter. I don't really understand why this is happening as PolylinePoint is a struct and should be allocated on the stack, so doing something like p.SetPoint(i, newPolylinePoint(.....   should stay away from any CG.Alloc. 

What should I do to reduce the GC allocs and spikes?

I am using version 3.2.3 (I haven't upgraded yet due to the breaking changes), is there an improvement in this regard in the newer versions? I checked the changelog but I didn't find anything.

Thank you!

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
3.2.3
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Answered

no performance improvement on the polylines in 4.x yet! I've planned to make the next big update to be centered around polylines, and allocation free updates will be one of the goals. right now you can't even use SetPoint without allocations, like you mention

Avatar
matei giurgiu

Awesome! Thanks for giving visibility about this :D

Avatar
Freya Holmér creator
  • Answer
  • Answered

no performance improvement on the polylines in 4.x yet! I've planned to make the next big update to be centered around polylines, and allocation free updates will be one of the goals. right now you can't even use SetPoint without allocations, like you mention