[release/10.0] - Port perf fixes to 10.0#554
Open
joeloff wants to merge 3 commits intodotnet:release/10.0from
Open
[release/10.0] - Port perf fixes to 10.0#554joeloff wants to merge 3 commits intodotnet:release/10.0from
joeloff wants to merge 3 commits intodotnet:release/10.0from
Conversation
Replace TextReader.ReadToEndAsync() + JsonDocument.Parse(string) with JsonDocument.ParseAsync(Stream) in both ProductCollection.GetAsync and Product.GetReleasesAsync. This eliminates the intermediate StringBuilder growth (~15 MB), the LOH string materialization from ToString (~13 MB), and the re-encoding back to UTF-8 for JsonDocument (~6 MB) per file parsed -- roughly 34 MB of transient allocations for a typical releases.json file.
ReleaseFile.GetHashCode() called Uri.GetHashCode() which forces EnsureUriInfo/CreateUriInfo (allocating UriInfo), GetComponentsHelper/ EnsureHostString (allocating host String), and MoreInfo objects. These lazy-parse allocations accounted for ~3.7 MB across 34 allocation tick samples during template loading. Use Address.OriginalString.GetHashCode() instead, which returns the already-stored string without triggering any URI parsing. The Equals method still uses Uri.operator== for correctness, but GetHashCode no longer forces the expensive parse path.
Store the URL as a string during JSON deserialization and lazily construct the Uri only when Address is accessed (for DownloadAsync or FileName). During template loading, ReleaseFile objects are created for every file in every release, but the Uri is never accessed -- only Hash, Name, and Rid are used for the Distinct() deduplication. The eager Uri construction allocated Char[] (CheckForUnicode), String (ParseScheme, host parsing), UriInfo, and MoreInfo objects per file -- visible across all three component types in the allocation trace. Also switch Equals to use string comparison on the URL instead of Uri.operator== to avoid forcing Uri construction during equality checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Porting changes from #545 to 10.0. To flow to Visual Studio, the updated assemblies need to go into the SDK template locator and MSBuild resolver.
Customer Impact
Reduces allocations in Visual Studio when process releases JSON data, improving performance. The library is used by both the SDK resolver and template locator. Additionally, the New Project Dialog also uses it to provide information related to EOL versions of .NET.
Regression
Testing
Manual testing.
Risk
Low