Fix cross-AppDomain TaskItem modifier cache regression#13493
Open
DustinCampbell wants to merge 1 commit intomainfrom
Open
Fix cross-AppDomain TaskItem modifier cache regression#13493DustinCampbell wants to merge 1 commit intomainfrom
DustinCampbell wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a .NET Framework Visual Studio allocation regression caused by copying an embedded modifier-cache struct across AppDomains by moving the cache onto the item objects themselves via an internal interface.
Changes:
- Replace
ItemSpecModifiers.Cachestruct with anIItemSpecModifierCacheinterface and update modifier computation to use it. - Implement per-item modifier caching directly on
TaskItem,ProjectItem,ProjectItemInstance.TaskItem, andTaskParameterTaskItem. - Refactor
ItemSpecModifiers.GetItemSpecModifierinto caching vs non-caching overloads and extract defining-project modifier resolution.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Utilities/TaskItem.cs | Moves derivable modifier caching onto TaskItem via IItemSpecModifierCache and clears cache on ItemSpec changes. |
| src/Shared/TaskParameter.cs | Updates TaskParameterTaskItem to use IItemSpecModifierCache for modifier caching. |
| src/Framework/ItemSpecModifiers.cs | Reworks modifier computation to support caching through IItemSpecModifierCache and adds a non-caching overload. |
| src/Framework/IItemSpecModifierCache.cs | Introduces internal interface for per-item derivable modifier caching across AppDomain boundaries. |
| src/Framework.UnitTests/FileUtilities_Tests.cs | Updates tests to use the new cache interface instead of the removed struct cache. |
| src/Build/Instance/ProjectItemInstance.cs | Implements cache interface on ProjectItemInstance.TaskItem, clears cache on spec changes, and copies cache on clone. |
| src/Build/Definition/ProjectItem.cs | Implements cache interface on ProjectItem and routes built-in metadata through the new cache API. |
| src/Build/Definition/BuiltInMetadata.cs | Switches built-in metadata APIs from ref Cache to IItemSpecModifierCache. |
Member
|
experimentally inserting to run speedometer at exp/dev/dustinca/fix-cross-appdomain-taskitem-cache branch (ETA results in 8h) |
Recently, ItemSpecModifiers.GetItemSpecModifier was changed to take a Cache struct rather than a single "string? fullPath" parameter. Unfortunately, this increases memory allocations to an unexpected degree -- especially in cross-AppDomain scenarios. This change reduces the size of the Cache struct to just a single FullPath field, which should remove the allocation regression.
3057496 to
3941d2b
Compare
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.
The ItemSpecModifiers.Cache struct I introduced with #13386 caused a surprising ~200 MB allocation regression in Visual Studio scenarios on .NET Framework. Essentially, when TaskItem (a MarshalByRefObject) cached modifiers in an embedded struct, there's a huge cost to copy that struct cross-AppDomain.
To fix the problem, reduce the Cache struct to just a single field to store the full path. This should effectively bring memory allocations back in line.