Remove instances of System.Linq to reduce GC allocation at runtime

Avatar
  • updated
  • Fixed

I have been using Shapes as a critical part of our VR game, for which I need to minimize GC allocations during gameplay.  After inspecting the GC allocations, I noticed that Shapes is using System.Linq as a shortcut in several spots.  However, this creates GC (JacksonDunstan.com | Just How Much Garbage Does LINQ Create?), so I would like to request that the code be refactored to use for / foreach loops instead of the System.Linq shortcuts.  I can definitely do this myself for my own use case, but figured it would be useful for folks in general.

EDIT: Specifically the one that was causing me issues was StrArrEquals in RenderState.cs.  I looked at the other ones, it's possible that the ones in Polyline could be removed too, but I don't use those so not sure how often that's called.

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
4.1.3
Reporting a bug? please specify Render Pipeline:
URP
Avatar
Freya Holmér creator
  • Fixed

I've fixed that specific case now - were there any other instances that were causing issues? (polylines aside - those have also been fixed for upcoming versions)

usually LINQ is mostly a concern in hot paths/update loops, so I tend to avoid using them there, but I do use them in one-time setups and in editor code