Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit StructValue resize allocations #2107

Merged

Conversation

clutterloh
Copy link
Contributor

We use TraceEvent to gather process-level event counters. I noticed in a recent trace that about 12% of our process memory allocations are due to resizing when we call DynamicTraceEventData.PayloadValue(int32)

In particular, the system.private.corelib.il!System.Collections.Generic.List`1[System.Collections.Generic.KeyValuePair`2[System.__Canon, System.__Canon]].AddWithResize(System.__Canon) and system.private.corelib.il!System.Collections.Generic.List`1[System.Collections.Generic.KeyValuePair`2[System.__Canon, System.__Canon]].set_Capacity(int32) frames caused by list resizing.

I noticed in the code that when GetPayloadValueAt(...) is called a StructValue is created and we go through a loop adding i KeyValuePairs corresponding to classInfo.FieldFetches.Length.
https://github.com/microsoft/perfview/blob/4685da655131acb73441f71ec19ea79ffa300ffa/src/TraceEvent/DynamicTraceEventParser.cs#L606C17-L612C18

Copy link
Member

@brianrob brianrob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this @clutterloh. This seems like a completely reasonable change that could have some good benefit.

@brianrob brianrob merged commit 9ffcfe8 into microsoft:main Aug 29, 2024
5 checks passed
@brianrob brianrob linked an issue Aug 29, 2024 that may be closed by this pull request
@clutterloh clutterloh deleted the LimitStructValueResizeAllocations branch August 29, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initializing StructValues with list size to save allocations
2 participants