Perf: Reorder RAR output metadata copies#12298
Merged
YuliiaKovalova merged 9 commits intoOct 27, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This performance optimization PR refactors the ResolveAssemblyReference (RAR) task to reduce CPU time and memory allocations when copying metadata between TaskItem instances. The changes leverage new copy-on-write (COW) cloning capabilities to minimize expensive ImmutableDictionary operations.
Key changes:
- Added
RemoveMetadataRangemethod to batch metadata removal operations - Reordered metadata operations to maximize COW efficiency by performing initial copies before modifications
- Consolidated metadata setting logic into iterator methods for better batching
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Framework/IMetadataContainer.cs | Added RemoveMetadataRange interface method |
| src/Framework/TaskItemData.cs | Added NotImplementedException stub for RemoveMetadataRange |
| src/Build/Instance/ProjectItemInstance.cs | Implemented RemoveMetadataRange using ImmutableDictionary.RemoveRange |
| src/Utilities/TaskItem.cs | Implemented RemoveMetadataRange with null/empty checks |
| src/Shared/TaskParameter.cs | Implemented RemoveMetadataRange as loop over individual removals |
| src/Tasks/AssemblyDependency/ReferenceTable.cs | Major refactoring of SetItemMetadata for performance optimization |
ccastanedaucf
commented
Aug 9, 2025
YuliiaKovalova
approved these changes
Oct 27, 2025
This was referenced Oct 27, 2025
This was referenced Nov 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes
Refactor of
ReferenceTable.SetItemMetadatato take advantage of new TaskItem COW cloning and batch updates, reducing total number of ImmutableDictionary operations and RAR e2e time.Before (CPU time in RAR

SetItemMetadata1,951ms)After (758ms aka -1.1s)

Before (allocations under TaskItem)

After (-288MB)

Context
ReferenceTable.SetItemMetadatacopies metadata from inputs (ProjectItemInstance.TaskItem) to RAR's primary and related file outputs (Utilities.TaskItem), with certain keys filtered out or removed depending on the output parameter.Since we now support
ImmutableDictionaryclones acrossTaskItemimplementations, we can significantly reduce CPU and allocations here by reordering the sequence of modifications and batching updates when possible, as each operation will always result in a newImmutableDictionaryinstance.Changes Made
RemoveMetadataRange(IEnumerable<string>)toIMetadataContainer, which forwards toImmutableDictionary.RemoveRange(IEnumerable<string>.TaskItemnow populates initial metadata rather thanEnumerateCommonMetadata().