Repository navigation
Look packages up concurrently, and parse NuGet responses with System.Text.Json - #709
Merged
Merged
Conversation
Each package's lookups were made one after another, so a run was mostly waiting on network latency. A 40 package Directory.Packages.props took 18-41s from an empty http cache. It now takes 2-3s, with the same changes, in the same order. - Prefetch starts the lookups for the central packages, the VersionOverrides across every csproj, and the tools, up to 16 at a time, ahead of the loops that apply them - LookupCache and RepositoryReader keep each lookup as a task, shared via SharedLookup.GetOrStart, so the loops await the lookup already in progress. A failed lookup is not kept, so a later call tries again, as before - The loops are unchanged and still go through the items in order, so edits, migrations, logged changes, the result and progress are as before - Disposing a Prefetch stops it starting lookups and waits for those started, so none outlive the SourceCacheContext - Loggers passed in must now be thread-safe. RecordingLogger takes a lock Also updates the SkipsMigrationWhenAlternativeAlreadyExists snapshot, since Azure.Storage.Common 12.29.1 has been published.
Turns on NuGet.Protocol's NuGet.UseSystemTextJsonDeserialization switch, via a RuntimeHostConfigurationOption so it is in the tool's runtimeconfig.json. NuGet.Protocol then parses the service index and registration metadata with System.Text.Json rather than Newtonsoft.Json. For a 40 package Directory.Packages.props, from an empty http cache: - Allocates about 39MB rather than 152MB - Peaks at about 83MB working set rather than 92MB, and 38MB private rather than 45MB - Runs about 0.1-0.4s faster, of about 2.5s The same changes are written. It applies only to the tool: PackageUpdateLib does not set it, so a caller such as Lode stays on NuGet's default unless it opts in. Newtonsoft.Json is still a dependency, via NuGet.Packaging.
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.
A run spent nearly all its time waiting on network latency, since each package's lookups were made one after another. This makes the lookups concurrent, and has the tool parse NuGet responses with System.Text.Json.
For a 40 package
Directory.Packages.props, from an empty NuGet http cache:The same 38 updates and 2 migrations are made. The props file written is byte for byte the same, and the change and warning lines are logged in the same order.
Look packages up concurrently
Prefetchstarts the lookups for the central packages, the VersionOverrides across every csproj, and the tools, up to 16 at a time (Prefetch.MaxConcurrentLookups), ahead of the loops that apply themLookupCacheandRepositoryReaderkeep each lookup as a task, shared viaSharedLookup.GetOrStart, so a loop awaits the lookup already in progress rather than making its own. A failed lookup is not kept, so a later call tries again, as beforeUpdateResultand progress callbacks are as beforePrefetch(await using) stops it starting lookups and waits for those started, so none outlive theSourceCacheContextParse NuGet responses with System.Text.Json in the tool
PackageUpdate.csprojturns on NuGet.Protocol'sNuGet.UseSystemTextJsonDeserializationswitch via aRuntimeHostConfigurationOption, so it is in the tool's runtimeconfig.json (checked in the packed nupkg). NuGet.Protocol then parses the service index and registration metadata with System.Text.Json, allocating about 39MB rather than 152MB for the 40 packages.It applies only to the tool. PackageUpdateLib does not set it, so Lode stays on NuGet's default unless it opts in. Newtonsoft.Json is still a dependency, via NuGet.Packaging.
For review
RecordingLoggernow takes a lockNUGET_USE_SYSTEM_TEXT_JSON_DESERIALIZATION=trueSkipsMigrationWhenAlternativeAlreadyExistssnapshot is updated for Azure.Storage.Common 12.29.1, published 2026-11-20. It fails on main too