handzlikchris / FastScriptReload

Hot Reload implementation for Unity. Iterate on code insanely fast without breaking play session. Supports any editor. 1. Play 2. Make change 3. See results
https://immersivevrtools.com/projects/fast-script-reload
MIT License
1.58k stars 113 forks source link

File Watcher allocates 100 KB per frame -> lag spikes on GC #116

Closed YellowTech closed 9 months ago

YellowTech commented 9 months ago

The file watcher allocates almost 100 KB per frame in an relatively empty unity project, which leads to large and very regular lag spikes when garbage collection occurs.

FOR ANYONE HAVING THIS ISSUE: enabling "incremental gc" will smooth out the lag spikes, making this a non-issue since this problem will not affect runtime builds anyway.

Nevertheless, it would be nice if this problem could be circumvented by using an allocation free algorithm. If the default file watcher is provided by unity or otherwise outside of your hand, maybe add a tip in the watcher menu to activate incremental gc.

Thank you very much for this piece of software, it makes Unity much more enjoyable!

Here is a deep profiler screenshot of the mentioned allocations. It appears that String.Split() is the main culprit: image

handzlikchris commented 9 months ago

Nice, thanks for raising that. There's a few issues with standard Unity file watchers unfortunately.

You can go to File Watchers menu and change it to Windows API (on most recent github version), there's also Custom Polling - but that's very simple implementation that watches files manually which will be even more resource intensive.

I'll close the issue as the plan is to move to WindowsAPI (on supported platforms) once it's considered stable.