Memoize copy-to-output-directory item filtering in graph predictor to improve perf#143
Open
derekantrican wants to merge 1 commit into
Open
Conversation
Cache the filtered CopyToOutputDirectory items per dependency ProjectInstance in GetCopyToOutputDirectoryItemsGraphPredictor. When multiple root nodes share transitive dependencies (common in large graphs), the same dependency's items were being filtered repeatedly across 6 item types. The cache uses ConcurrentDictionary<ProjectInstance, Lazy<CopyItemResult[]>>: - ConcurrentDictionary for thread-safe access from parallel graph node processing - Lazy<> ensures the filtering work runs exactly once per dependency under contention - Results stored as immutable arrays of (InputPath, TargetPath) structs - Output paths (which depend on the caller's OutDir) are computed at report time Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
Do you have any benchmarks to share? |
Contributor
Author
|
@dfederm - I don't right now (been swamped with a lot of other things), but if that's absolutely necessary then I can work on generating some. I would have to figure out what needs to be done to build the library and put it in the right place for the Office build system |
dfederm
reviewed
May 7, 2026
| internal const string MSBuildCopyContentTransitivelyPropertyName = "MSBuildCopyContentTransitively"; | ||
| internal const string HasRuntimeOutputPropertyName = "HasRuntimeOutput"; | ||
|
|
||
| private static readonly string[] CopyItemNames = new[] |
Contributor
Author
There was a problem hiding this comment.
With the memoization refactor, BuildCopyItemsCore needs to iterate over each item to build the cached results. Extracting them into a shared array (as opposed to the 6 separate ReportCopyToOutputDirectoryItemsAsInputs calls that existed before) avoids duplicating the list of item names in two places and makes it easier to keep them in sync if a new item type is added later.
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.
Cache the filtered
CopyToOutputDirectoryitems per dependency ProjectInstance inGetCopyToOutputDirectoryItemsGraphPredictor. When multiple root nodes share transitive dependencies (common in large graphs), the same dependency's items were being filtered repeatedly across 6 item types.The cache uses
ConcurrentDictionary<ProjectInstance, Lazy<CopyItemResult[]>>:ConcurrentDictionaryfor thread-safe access from parallel graph node processingLazy<>ensures the filtering work runs exactly once per dependency under contention(InputPath, TargetPath)structs