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

Attempt to move several data structures to be immutable #5930

Merged
merged 6 commits into from
Oct 17, 2024

Conversation

ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Jul 22, 2024

Bug

Fixes: NuGet/Home#13647
Reduces allocations during solution load in VS

Description

Modified several data structures to be immutable, such that the PackageSpec.Clone operation can allocate significantly less. The scenario is outlined in the bug, but it's essentially cutting a 2-3% of allocations of solution load from the solutions I've tested.

This change is a bit viral, and ended up being more involved than I had originally thought it would be, but it feels like this ends up not only being more performant, but also lends these data structures to be more sanely reasoned about.

*** before changes ***
image

*** with changes ***
image

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.

@dotnet-policy-service dotnet-policy-service bot added the Community PRs created by someone not in the NuGet team label Jul 22, 2024
@ToddGrun ToddGrun marked this pull request as ready for review July 23, 2024 15:17
@ToddGrun ToddGrun requested a review from a team as a code owner July 23, 2024 15:17
Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

If public APIs were not a consideration, this would be something very easy to accept.

We'll need to internally decide about the risk.

I did leave some feedback on the implementation.
Feel free to ping me offline you need any more clarifications.

nkolev92
nkolev92 previously approved these changes Aug 1, 2024
Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

I don't really have any feedback here.

This is a great change and something we've wanted to do for a while.
This should allow us to improve the no-op calculation eventually since we're primarily dealing with immutable objects (nearly all of them are I think).

We'll want to run some manual validation and get sign off as this is a binary breaking change.
There are ways we can reduce that footprint (by obsoleting certain method and using the new ones only), but some places, like the types becoming immutable there's simply not other way.

@nkolev92
Copy link
Member

Team Triage: Given the recent chnages in e68fb0f, we want to minimize the code churn in the restore area.
We want to take this in the next release.

We'd need to rebase closer to when we'd be ready for the next release.

@nkolev92 nkolev92 self-assigned this Aug 12, 2024
@nkolev92 nkolev92 added the Merge next release PRs that should not be merged until the dev branch targets the next release label Aug 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Aug 20, 2024
@nkolev92 nkolev92 removed the Merge next release PRs that should not be merged until the dev branch targets the next release label Sep 27, 2024
@dotnet-policy-service dotnet-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Sep 27, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 4, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 4, 2024
@nkolev92 nkolev92 marked this pull request as draft October 7, 2024 16:22
@nkolev92 nkolev92 force-pushed the SwitchToImmutable branch 3 times, most recently from ebb3f9d to 1b476ad Compare October 11, 2024 21:08
@nkolev92 nkolev92 marked this pull request as ready for review October 11, 2024 21:09
@nkolev92
Copy link
Member

@NuGet/nuget-client This is ready for review.

zivkan
zivkan previously approved these changes Oct 16, 2024

for (var i = 0; i < spec.Dependencies.Count; i++)
{
// existingDependency.LibraryRange.VersionRange = range;
Copy link
Member

Choose a reason for hiding this comment

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

This looks like old code (line 43) that was commented out during development, rather than an intentional comment. If it's an intentional comment, it needs improvement to be more understandable.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, fixed now.

@nkolev92 nkolev92 merged commit 15691b7 into NuGet:dev Oct 17, 2024
30 checks passed
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.

PERF: NuGet Cloning operations are showing heavily in allocations during VS solution load
4 participants