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

Remove allocations from PackageSource.Source setter #5271

Merged

Conversation

drewnoakes
Copy link
Contributor

@drewnoakes drewnoakes commented Jun 23, 2023

Bug

Fixes: NuGet/Home#12692
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1840739
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1840740

Regression? Last working version:

Description

the PackageSource.Source property setter computes a hash code that includes string values in a case-insensitive way. It used to do that by allocating upper case strings, then computing the hashes on them. There's no need to allocate those temporary strings, as you can just use a StringComparer to compute the same value more efficiently.

To remove these allocations I've delegated the hash code computation to HashCodeCombiner, which won't allocate (for ASCII strings, at least).

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

the `PackageSource.Source` property setter computes a hash code that includes string values in a case-insensitive way. It used to do that by allocating upper case strings, then computing the hashes on them. There's no need to allocate those temporary strings, as you can just use a `StringComparer` to compute the same value more efficiently.

To remove these allocations I've delegated the hash code computation to `HashCodeCombiner`, which won't allocate (for ASCII strings, at least).
@drewnoakes drewnoakes requested a review from a team as a code owner June 23, 2023 01:16
@nkolev92 nkolev92 merged commit 86c78b6 into dev Jun 28, 2023
@nkolev92 nkolev92 deleted the dev-drnoakes-1840739-PackageSource-SetSource-allocations branch June 28, 2023 19:02
@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.

Remove allocations from PackageSource.Source setter
4 participants