Perf: Avoid unnecessary ProjectMetadataInstance allocations#12599
Merged
JanProvaznik merged 2 commits intodotnet:mainfrom Oct 7, 2025
Merged
Perf: Avoid unnecessary ProjectMetadataInstance allocations#12599JanProvaznik merged 2 commits intodotnet:mainfrom
JanProvaznik merged 2 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes performance by eliminating unnecessary ProjectMetadataInstance allocations when retrieving metadata values in MSBuild's BatchingEngine. The changes refactor metadata retrieval methods to directly return escaped string values instead of creating intermediate ProjectMetadataInstance objects.
- Refactored
GetMetadataEscapedto use string-based methods instead of metadata instance objects - Updated
GetItemDefinitionMetadatato return strings directly asGetItemDefinitionMetadataEscaped - Optimized
IMetadataTable.GetEscapedValueIfPresentto avoid unnecessary metadata object creation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Build/Instance/ProjectItemInstance.cs | Refactored metadata retrieval methods to work with escaped strings directly instead of allocating ProjectMetadataInstance objects |
| src/Build/Instance/ProjectItemDefinitionInstance.cs | Optimized GetEscapedValueIfPresent to return string values directly from metadata dictionary |
Contributor
Author
|
FYI the test failure is unrelated |
Member
|
validating speedometer in https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/676659 |
JanProvaznik
approved these changes
Oct 7, 2025
Member
JanProvaznik
left a comment
There was a problem hiding this comment.
lgtm from clear code standpoint and validation in VS that it improves the scenario it's supposed to ![]()
This was referenced Feb 23, 2026
Merged
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.
Context
Fixes an allocation regression in a VS C++ scenario due to allocating
ProjectMetadataInstancewhen retrieving metadata values inBatchingEngine.Here's the trace pulled from VcxprojReader when loading the UE52 test solution in VS:

Changes Made
This refactors various methods so that
ProjectItemInstance.GetMetadataEscapedcan directly retrieve the escaped string value without intermediateProjectMetadataInstanceallocations.