Performance: Pre-calculate or cache MyDefinitionId.ToString results

Viktor Ferenczi shared this bug 10 months ago
Reported – Awaiting fix

Game version: 1.200.032

Method: MyDefinitionId.ToString

This method is called frequently, it also allocates memory. There are only 1000-1500 distinct definition IDs to format (depending on mods), so these are cacheable without expiration.

Measured 1.9% CPU load just on this formatting method on a multiplayer server, which is too much for basically nothing.

Replies (2)

photo
1

Hello, Viktor!

Thank you for letting us know about this. I have reported this internally.

Kind Regards

Laura, QA Department

photo
1

Hello, Viktor!


I haven't found situation where it can drain 1.9% CPU. How do you measure?

If you use dot.Trace, could you please attach file?


Kind Regards

Gregory Smirnov

photo
1

That was measured of a local copy of a big server having hundreds of grids.

What I wrote in the description applies regardless. There is a good opportunity to cache the formatted definition IDs here, which will give some speedup in all cases.

Main reason for the speedup is that string formatting allocates memory, while retrieving the already formatted string from a dictionary does not allocate any memory. It removes some GC pressure, which always helps with performance regardless.

photo
Leave a Comment
 
Attach a file