Lag on connector lock/unlock and rotor head attach/detach due to grid group changes
Game version: 1.200.027
Test world and dotTrace analysis available. Root cause determined.
Problem: Lag on connector lock/unlock and rotor head attach/detach due to grid group changes causing massive main thread workload, which could easily be deferred to worker threads with minimal consequences.
How to reproduce:
- Load any of the test worlds. They contain two heavy production blocks connecting/disconnecting every second (2 seconds time period in total). One world connects them with two connectors, the other one with a single advanced rotor. Same story.
- Just stay next to the grid and watch the simulation thread load (Shift-F11).
- Fly around and feel the lag.
- Run dotTrace and sample for 10 seconds.
- Look for the methods marked in yellow on the attached screenshot.
Solution: Disable MyResourceDistributorComponent.UpdateBeforeSimulation while moving grids between grid groups. Same story for all other related updates which can be triggered by on add/remove event handers. They should be marked for recalculation and a worker thread would do it later. Nobody dies if the conveyor network is not up to date for a few frames.