Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce allocations under UnresolvedMessages.GetMessageAsync #6264

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Feb 11, 2025

Bug

Fixes: NuGet/Home#14094

Description

Reduce allocations under UnresolvedMessages.GetMessageAsync

This method shows as 0.6% (95 MB) of all VS allocations from VS start until opening the file in the CSharpEditingTest speedometer test. I think the changes in this PR should get rid of the majority of those allocations.

The primary change here is to not use a SortedSet, but instead have the code do the sorting when it's needed. The SortedSet ctor allocates a fair bit, and each node in the set requires an allocation for the wrapping node.

As for the concern of now needing to walk the whole collection in GetBestMatch as the collection is no longer sorted, the old code was doing that anyways. Both the FirstOrDefault and Last methods are IEnumerable extensions that potentially walk the full collection.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

This method shows as 0.6% (95 MB) of all VS allocations from VS start until opening the file in the CSharpEditingTest speedometer test. I think the changes in this PR should get rid of the majority of those allocations.

The primary change here is to not use a SortedSet, but instead have the code do the sorting when it's needed. The SortedSet ctor allocates a fair bit, and each node in the set requires an allocation for the wrapping node.

As for the concern of now needing to walk the whole collection in GetBestMatch as the collection is no longer sorted, the old code was doing that anyways. Both the FirstOrDefault and Last methods are IEnumerable extensions that potentially walk the full collection.
@ToddGrun ToddGrun requested a review from a team as a code owner February 11, 2025 20:32
@dotnet-policy-service dotnet-policy-service bot added the Community PRs created by someone not in the NuGet team label Feb 11, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Community PRs created by someone not in the NuGet team label Feb 11, 2025
@ToddGrun
Copy link
Contributor Author

Test insertion based on commit 1 from which to get speedometer numbers: https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/610229

@Nigusu-Allehu
Copy link
Contributor

/azp run NuGet.Client-PrivateDev

Copy link

No pipelines are associated with this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PRs created by someone not in the NuGet team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnresolvedMessages.GetMessageAsync is allocating more heavily than necessary
2 participants