⚡ Bolt: Replace expensive FindObjectsOfType with Rack cache#21
Conversation
Replaces the expensive O(N) `UnityEngine.Object.FindObjectsOfType<Rack>()` call which blocks the main thread and causes severe GC pressure in Unity/IL2CPP with an O(1) thread-safe static cache populated via Harmony `Awake` and `OnDestroy` patches. This eliminates major performance hitches when counting or querying Racks in the API and Lua scripts.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Replaces the expensive
UnityEngine.Object.FindObjectsOfType<Rack>()call across the codebase with an O(1) thread-safe static cache inRackPatch. The cache tracks active Racks by hooking into theirAwakeandOnDestroylifecycle methods via Harmony.🎯 Why:
FindObjectsOfTypeis an O(N) operation that traverses every active GameObject in the scene. In late-game saves with thousands of objects, frequent API or Lua polling of Rack counts or data causes significant main thread hitches and severe Garbage Collection pressure due to array allocation.📊 Impact:
🔬 Measurement:
GregAPI.GetRackCount()orgreg.rack.count(). You will see time drop from several milliseconds (in large saves) to negligible nanoseconds.dotnet build gregCore.csproj -c Release).PR created automatically by Jules for task 292053595981774687 started by @mleem97