Skip to content

Conversation

@krzychu124
Copy link
Member

@krzychu124 krzychu124 commented Mar 11, 2023

  • delete Release conditional Log methods that create garbage regardless of condition
  • replace garbage generating calls with garbage free alternatives, use PoolList<T> where applicable
  • refactor delegates capturing method variables either by removing delegate or forcing delegate instantiation to last moment
  • correct Assertion type to avoid boxing, fix possible NullReferenceException while logging an Exception 😂
  • skip queuing notify actions if there's no listeners in the Notifier class. Avoids creating useless Simulation Action and also eliminates garbage that would be generated by instantiating objects args and Action delegate itself

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

…gate or forcing delegate instantiation to last moment

Notice that debug guarded calls capturing local variable can still trigger generation of <>DisplayClass helper classes including their instantiation even when not used explicitly anywhere in the method
…eating useless Simulation Actions and also eliminates garbage that would be generated by instantiating objects
@krzychu124 krzychu124 added code cleanup Refactor code, remove old code, improve maintainability performance Make it faster! labels Mar 11, 2023
@krzychu124 krzychu124 added this to the 11.7.4.0 milestone Mar 11, 2023
@krzychu124 krzychu124 self-assigned this Mar 11, 2023
@krzychu124 krzychu124 requested a review from DaEgi01 March 11, 2023 14:44
@krzychu124 krzychu124 merged commit 8276bab into master Mar 12, 2023
@krzychu124 krzychu124 deleted the bugfix/eliminate-memory-pressure-hot-path branch March 12, 2023 19:39
@krzychu124 krzychu124 mentioned this pull request Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code cleanup Refactor code, remove old code, improve maintainability performance Make it faster!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants