Siccity / xNode

Unity Node Editor: Lets you view and edit node graphs inside Unity
MIT License
3.3k stars 582 forks source link

Optimizations/memandgc #358

Closed nostek closed 1 year ago

nostek commented 1 year ago

A few memory and gc optimizations that only makes a difference when you have a larger project, but does indeed make a difference.

Siccity commented 1 year ago

Sorry for the delay. I tested your changes and it gave me some errors in Unity 2020.3.7f1

Assets\Submodules\xNode\Scripts\NodeDataCache.cs(40,29): error CS1061: 'Dictionary<string, NodePort>' does not contain a definition for 'EnsureCapacity' and no accessible extension method 'EnsureCapacity' accepting a first argument of type 'Dictionary<string, NodePort>' could be found (are you missing a using directive or an assembly reference?)
nostek commented 1 year ago

Sorry for the delay. I tested your changes and it gave me some errors in Unity 2020.3.7f1

Assets\Submodules\xNode\Scripts\NodeDataCache.cs(40,29): error CS1061: 'Dictionary<string, NodePort>' does not contain a definition for 'EnsureCapacity' and no accessible extension method 'EnsureCapacity' accepting a first argument of type 'Dictionary<string, NodePort>' could be found (are you missing a using directive or an assembly reference?)

My bad! Thought EnsureCapacity had existed for a while.. added ifdef guards around then. The function is introduced in net standard 2.1 https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.ensurecapacity?view=net-7.0 And Unity upgraded to 2.1 in 2021.3.

nostek commented 1 year ago

I cant see why PortDataCache needs to be serialized, so I removed that and prefilled it with dictionaries instead of generating them in UpdatePorts.

Siccity commented 1 year ago

Thanks! 😄