fmod / fmod-for-unity

FMOD Studio integration with Unity.
https://fmod.com/resources/documentation-unity
MIT License
181 stars 38 forks source link

Avoid minor GC Alloc by adding basic utilities #36

Closed rparnas closed 2 years ago

rparnas commented 4 years ago

I noticed the RuntimeManager has GC Alloc of a few hundred bytes per frame which isn't a lot but it is an unnecessary distraction for anyone optimizing performance.

For example, RunTimeManager calls GetSetting in Settings.cs, which has the line

T t = list.Find((x) => x.Platform == platform);

which causes the alloc. A simple utility like below would avoid this:

T FindInList<T>(List<T> list, Predicate<T> predicate)
{
  for (var i = 0; i < list.Count; i++)
  {
    var item = list[i];
    if (predicate(item))
    {
      return item
    }
  }
  return default(T);
}

Can anyone provide clarity as to where such a utility would go / how it should be set up for the coding style of this project? A new file called "BasicUtilities.cs" perhaps?

fmod-mathew commented 2 years ago

The entire settings system has been replaced in newer versions of the integration.