Skip to content

Conversation

@ttstanley
Copy link
Contributor

Fixes # Captures that lead to allocations.

Context

Based on a trace was able to see that allocations from captures that were from using linq without the correct context.

Changes Made

Manually created a list instead of using the where clause to create one.
Also moved over to grabbing the underlying struct enumerator when possible to avoid boxing.

Testing

Looked at the dll in ILSPY to verify change in closures.

Before. (Display Class shows a capture)
image

After (no more DisplayClass)
image

Notes

Copilot AI review requested due to automatic review settings June 2, 2025 23:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Optimizes metadata removal in ApplyMetadataModificationsToItem by replacing the LINQ-based approach with manual loops to eliminate closures and avoid boxing when iterating over CopyOnWritePropertyDictionary.

  • Replaced a single LINQ call with explicit foreach loops
  • Added special handling for CopyOnWritePropertyDictionary<ProjectMetadataInstance> to leverage its struct enumerator

@rainersigwald
Copy link
Member

In general for this class of issue, I'm willing to accept on faith that there are allocating constructs--what is interesting is how allocatey the codepath is relative to full execution. Can you focus on that in the motivation for future PRs?

…y bigger allocation of list, leaving as default allocation size.
@SimaTian SimaTian merged commit 4eea732 into dotnet:main Jun 9, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants