⚡ Bolt: Replace expensive FindObjectsOfType with O(1) NetworkMap lookups - #221
⚡ Bolt: Replace expensive FindObjectsOfType with O(1) NetworkMap lookups#221mleem97 wants to merge 2 commits into
Conversation
Replaced O(N) `UnityEngine.Object.FindObjectsOfType<T>()` calls in `GameHooks.EnsureAllRackPositionUIDs()` with O(1) lookups via `Il2Cpp.NetworkMap.instance` collections (`servers`, `switches`).
|
👋 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. |
Up to standards ✅🟢 Issues
|
Replaced O(N) `UnityEngine.Object.FindObjectsOfType<T>()` calls in `GameHooks.EnsureAllRackPositionUIDs()` with O(1) lookups via `Il2Cpp.NetworkMap.instance` collections (`servers`, `switches`). `FindObjectsOfType` is extremely slow as it loops through all active GameObjects in the scene. During heavy mod sync operations, this causes significant stutter. The game already caches these objects in `NetworkMap.instance`. Significantly reduces frame drops and CPU spikes during WorldSync / RackPositionUID validation by using direct dictionary iteration.
💡 What: Replaced O(N)
UnityEngine.Object.FindObjectsOfType<T>()calls inGameHooks.EnsureAllRackPositionUIDs()with O(1) lookups viaIl2Cpp.NetworkMap.instancecollections (servers,switches).🎯 Why:
FindObjectsOfTypeis extremely slow as it loops through all active GameObjects in the scene. During heavy mod sync operations, this causes significant stutter. The game already caches these objects inNetworkMap.instance.📊 Impact: Significantly reduces frame drops and CPU spikes during WorldSync / RackPositionUID validation by using direct dictionary iteration.
🔬 Measurement: Observe CPU frametime consistency during mod synchronizations and compare profiler data of
EnsureAllRackPositionUIDsexecution time before and after.PR created automatically by Jules for task 11535858758850956507 started by @mleem97