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 some allocations under HttpFileSystemBasedFindPackageByIdResource.ConsumeFlatContainerIndexAsync #6265

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

Conversation

ToddGrun
Copy link
Contributor

Bug

NuGet/Home#14095

Fixes:
Reduces allocation in this codepath

Description

  1. Swtiched to using Utf8JsonStreamReader instead of newtonsoft for reading some json. However, this class wasn't available from what I could determine, so I took the easy route of just duplicating the code. This isn't great, and I'd love guidance on a better way to access this.

  2. Changed PackageInfo.ContentUri to be calculated on a deferred basis as it's very expensive to calculate and is used quite infrequently (I saw about 0.1% of PackageInfo objects created actually get queried for that data)

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.

@ToddGrun ToddGrun requested a review from a team as a code owner February 11, 2025 20:44
@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
var normalizedVersionString = Identity.Version.ToNormalizedString();
string idInLowerCase = Id.ToLowerInvariant();

var builder = StringBuilderPool.Shared.Rent(256);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roughly 50% of the string builders used in this codepath end up exceeding the 256 char limit, and thus aren't released back to the pool. I didn't address it in this PR, as delay calculating this ends up getting rid of the vast majority of the work, but it might be worth considering upping that 256 char limit used in StringBuilderPool.

/// This struct is used to read over a memory stream in parts, in order to avoid reading the entire stream into memory.
/// It functions as a wrapper around <see cref="Utf8JsonStreamReader"/>, while maintaining a stream and a buffer to read from.
/// </summary>
internal ref struct Utf8JsonStreamReader
Copy link
Contributor Author

Choose a reason for hiding this comment

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

internal ref struct Utf8JsonStreamReader

I didn't like duplicating this class, but I wasn't sure how to get access to it otherwise.

@jeffkl jeffkl self-assigned this Feb 11, 2025
@ToddGrun
Copy link
Contributor Author

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

@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 Feb 19, 2025
@jeffkl jeffkl 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 Feb 19, 2025
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.

2 participants