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

Don't allocate temporaries in FrameworkNameProvider.GetVersionString #5250

Merged

Conversation

drewnoakes
Copy link
Contributor

@drewnoakes drewnoakes commented Jun 19, 2023

Bug

Fixes: NuGet/Home#12685
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1837332

Regression? Last working version: N/A

Description

Previously FrameworkNameProvider.GetVersionString would heap allocate a Stack<int>, a few enumerators, and a copy of the stack (for a call to Linq's Reverse).

With this change all state required to produce the version string is kept on the stack.

The unit test coverage for this method has been increased.

Also the allocation of an empty Version was removed in the Try* methods when they return false, to make them match their signatures and avoid a wasted allocation. Consuming code in this repo has been reviewed, and the behaviour captured in unit tests.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@drewnoakes drewnoakes requested a review from a team as a code owner June 19, 2023 06:44
jeffkl
jeffkl previously approved these changes Jun 19, 2023
nkolev92
nkolev92 previously approved these changes Jun 19, 2023
src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs Outdated Show resolved Hide resolved
@drewnoakes drewnoakes dismissed stale reviews from nkolev92 and jeffkl via 998ccd3 June 20, 2023 03:09
@drewnoakes drewnoakes force-pushed the dev-drnoakes-1837332-framework-version-string-allocations branch from 2649cd4 to 998ccd3 Compare June 20, 2023 03:09
nkolev92
nkolev92 previously approved these changes Jun 21, 2023
src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs Outdated Show resolved Hide resolved
Previously this would allocate a stack, enumerators, and a copy of the stack (for a call to Linq's `Reverse`).

With this change all state required to produce the version string is kept on the stack.

The unit test coverage for this method has been increased.

Also the allocation of an empty `Version` was removed in the `Try*` methods when they return false, to make them match their signatures and avoid a wasted allocation. Consuming code in this repo has been reviewed, and the behaviour captured in unit tests.
@drewnoakes drewnoakes force-pushed the dev-drnoakes-1837332-framework-version-string-allocations branch from 998ccd3 to d44c1b9 Compare June 21, 2023 00:54
@nkolev92 nkolev92 requested a review from jeffkl June 21, 2023 18:44
@nkolev92 nkolev92 assigned nkolev92 and unassigned nkolev92 Jun 21, 2023
@nkolev92
Copy link
Member

@jeffkl Rerequesting review from you.
If you approve, feel free to merge.

@nkolev92 nkolev92 enabled auto-merge (squash) June 28, 2023 19:06
@nkolev92
Copy link
Member

Jeff is out, enabling auto merge.

@nkolev92 nkolev92 merged commit ddce289 into dev Jun 28, 2023
@nkolev92 nkolev92 deleted the dev-drnoakes-1837332-framework-version-string-allocations branch June 28, 2023 20:00
@aortiz-msft aortiz-msft added the Community PRs created by someone not in the NuGet team label Aug 2, 2023
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.

FrameworkNameProvider.GetVersionString boxing enumerator
4 participants