CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
563 stars 85 forks source link

Eliminate memory pressure/garbage generation in sim performance critical path #1731

Closed krzychu124 closed 1 year ago

krzychu124 commented 1 year ago

Important note after checking compiled code in Release target

Debug guarded calls with lambdas or delegates capturing local variable (debugOverlay in UpdatePathTargetPositionsPatch.cs captures Bezier3 variable) can still trigger generation of <>DisplayClass helper classes, and most importantly use the instance of helper class to move captured variable around even if debug guarded code is not used explicitly anywhere in the method.

Other notes

Lambda/Delegate capturing local variable generates <>DisplayClass which instance in most cases is created in the first line of the method, regardless of where it be actually used, so compiler will generate instantiation code just for passing captured value around, even if you guard the explicit call with multiple conditions, including const.

TODO for the future PR

Redesign SegmentTraverser and SegmentLaneTraverser since currently they are multi-level garbage generators with lambdas capturing other lambdas, capturing local variables, not to mention that one runs recursively. Used on the main thread, mostly for displaying mod overlays like clickable Speed limits signs handles, Parking restrictions etc.

Build ZIP