Performance: Unnecessary updates during grid merge and paste operations
Game version: 1.200.025
PC: Ryzen 3800X, 64GB RAM, 3080Ti, 2TB NVMe, good liquid cooling
Problem: Expensive update operations are enabled during merge and paste operations, slowing it down a lot in case of grids with many blocks, especially with lots of conveyor ports.
How to reproduce:
- Run the game with a sampling timeline profiler.
- Load the test world attached, it has a single huge grid. This is a somewhat pathological test case to amplify the problem, so it shows up prominently in the profiler.
- Start profiler sampling.
- Copy the grid at one end of the long armor row and paste it over the other end, effectively doubling the grid. This operation took about 170 seconds on my PC, so be patient.
- Stop profiler sampling.
- Look for the most prominent uses of CPU time in user code (not the sleeps or I/O).
- Notice the excessive updates during the merge.
Workaround:
There is a workaround for this issue in the Performance Improvements plugin I'm working on.
It disables the MyConveyorLine.UpdateIsWorking method while any grid merging operation is in progress. It considerably reduces the merge time of grids with conveyor systems.
At the end of MyCubeGrid.MergeGridInternal it calls GridSystems.ConveyorSystem.FlagForRecomputation() on the grid to force recalculating all IsWorking values to fix any side-effects this workaround may have.
In order to eliminate further early updates the patch also sets MySession.Static.m_updateAllowed to false while MyCubeGrid.PasteBlocksServer is running. It eliminates a lot of computations until the paste is done, making it faster overall.
These two fixes combined makes the paste operation in my test case to complete in about 60 seconds instead of the original 170 seconds, a significant speedup.
Please see the dotTrace screenshots attached for comparison. Notice that the capture with the fix is much shorter, because the paste completed faster.
I'm aware that this is most likely not be the proper fix for the problem, but this is what I can get with runtime patching in a plugin. I hope it helps to develop the proper fix.
Please feel free to reach out in case of questions.
Hello, Viktor!
Thanks for letting us know. Issue was reported internally.
Kind Regards
Keen Software House: QA Department
Hello, Viktor!
Thanks for letting us know. Issue was reported internally.
Kind Regards
Keen Software House: QA Department
Replies have been locked on this page!