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

Initializing StructValues with list size to save allocations #2106

Closed
clutterloh opened this issue Aug 29, 2024 · 1 comment · Fixed by #2107
Closed

Initializing StructValues with list size to save allocations #2106

clutterloh opened this issue Aug 29, 2024 · 1 comment · Fixed by #2107

Comments

@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

Is there anything preventing us from adding a constructor to StructValue that lets us specify an initial size and avoid all the reallocations when resizing the internal m_values list?

@clutterloh
Copy link
Contributor Author

#2107

@brianrob brianrob linked a pull request Aug 29, 2024 that will close this issue
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 a pull request may close this issue.

2 participants