This object is in archive! 

Performance: MySpinWait.SpinOnce is eating the CPU

Guest shared this bug 2 years ago
Won't Fix

Game version: 1.200.025

Method: MySpinWait.SpinOnce


Problem: MySpinWait.SpinOnce is eating a lot of CPU whenever lock contention is high due to heavy threaded workload, making the situation worse by trashing the cache and heating up the CPU with useless workload.

How to reproduce:

  1. Load the attached test world. (It will load a bit slowly.) It contains a single huge grid.
  2. Copy-paste the grid onto itself (merge). It will take ~3 minutes to complete.
  3. Use JetBrains dotTrace or another profiler to monitor the performance.
  4. You will see that SpinOnce consumed a lot of CPU during the second phase of paste.

See the Main thread load between 02:00 and 02:40 (mm:ss) on the attached dotTrace screenshots.


Solution: Use Thread.Sleep(1) sooner to properly release the CPU.

Tested an alternative implementation: Search for the MySpinWaitPatch.cs in the Performance Improvements plugin.

Please feel free to reach out in case of questions.

Replies (3)

photo
1

For completeness: The PC I am running the profiling on is Ryzen 3800X, 64GB RAM, 3080Ti, 2TB NVMe, good liquid cooling.

photo
1

Profiling output to compare the original SpinWait.SpinOnce algorithm with my attempt to eliminate the excess spinning on the Main thread during world load.

The new algorithm succeeded in that, but later while the game is running the simulation load is higher.

There is not clear conclusive result that I can improve on the existing SpinOnce algorithm.

I'm giving up on this fix now.

You can close this ticket.

photo
1

Hello, Viktor,

thanks for letting us know and even more for coming back with the comment.

Will close the thread as requested.

Kind Regards

Keen Software House: QA Department

Leave a Comment
 
Attach a file