applejag / Newtonsoft.Json-for-Unity.Converters

Converters of common Unity types for Newtonsoft.Json. Goes hand in hand with jilleJr/Newtonsoft.Json-for-Unity
https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters
MIT License
322 stars 36 forks source link

Package causes large performance spike on assembly reload #77

Closed tomkail closed 9 months ago

tomkail commented 11 months ago

Hi! We've been doing some profiling to improve our editor reload speeds and we spotted that this package is causing a fairly large spike (~1s!) when assemblies are reloaded.

A main cause seems to be the use of string comparison in FindCustomConverters/FindUnityConverters. The code type.Namespace?.StartsWith("Newtonsoft.Json") runs around 100k times in our project. We had hoped to at least prevent searching for custom converters (which we don't have) by disabling them in the settings file but the filtering step occurs after searching for the assets, which means that doesn't help.

I've not used it myself, but I hear Unity's TypeCache class might be a good solution for this problem.

image

M1 Macbook Pro 2021 Converter package version 1.5.1

applejag commented 11 months ago

Really interesting find!

Will take a look at this. Thanks for the hint on TypeCache

applejag commented 9 months ago

Marking as closed by #78

applejag commented 9 months ago

Usage of TypeCache has been added in v1.6.0.

Do note that the TypeCache was first introduced in Unity 2019.2. This package falls back to the slower implementation on older Unity versions.

You can now also completely opt-out of this Assembly scanning code via the settings file:

image

Package is available at:

Enjoy :)