-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Reduce allocations in TaskExecutionHost #11804
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR reduces memory allocations in TaskExecutionHost by optimizing how task item metadata is enumerated and escaped.
- Introduces specialized logic for handling CopyOnWriteDictionary and Dictionary types in metadata enumeration.
- Adds a new local function to yield escaped key-value pairs with minimal allocations.
I think this parenthesis was deleted by error. If it was a different one, more thorough look will be needed
@@ -1423,9 +1424,26 @@ private void GatherTaskItemOutputs(bool outputTargetIsItem, string outputTargetN | |||
|
|||
static IEnumerable<KeyValuePair<string, string>> EnumerateMetadata(IDictionary customMetadata) | |||
{ | |||
foreach (DictionaryEntry de in customMetadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the penalty for using the interface here please? Is it boxing in this case or something else?
(e.g. from what I read, we use specialized iterations based on type, so I assume there is something to be gained, hence the boxing question)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal here is to avoid boxing the struct enumerator of these collections. In sufficiently hot paths, the allocations can really add up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if the parenthesis fix worked.
Otherwise the tests will fail again and revisit will be needed.
Fixes #
Context
Changes Made
Testing
Notes