Repository navigation
Use System.Text.Json for runtime graph reading - #7717
Merged
Merged
Conversation
zivkan
reviewed
Sep 18, 2026
baronfel
force-pushed
the
baronfel-aot-runtime-graph-reader
branch
3 times, most recently
from
September 21, 2026 15:40
37e814d to
dc2f274
Compare
zivkan
reviewed
Sep 22, 2026
Read runtime graph files and streams with a buffered UTF-8 reader while retaining the obsolete Newtonsoft-backed TextReader compatibility API. Share allocation-free UTF-8 BOM normalization with explicit ownership, preserve legacy JSON semantics, and retain NativeAOT coverage. Route every public package spec reader overload through the shared UTF-8 normalization path. Preserve diagnostics and stream ownership without the implicit JToken conversion that rooted Newtonsoft.Json in NativeAOT applications. Use native System.Text.Json positions for parser exceptions and calculate semantic error locations only when needed. Co-authored-by: Copilot App <[email protected]>
baronfel
force-pushed
the
baronfel-aot-runtime-graph-reader
branch
from
September 23, 2026 19:08
dc2f274 to
faca284
Compare
zivkan
reviewed
Sep 24, 2026
baronfel
force-pushed
the
baronfel-aot-runtime-graph-reader
branch
from
September 24, 2026 14:56
faca284 to
a82e2e8
Compare
Remove the redundant UTF-8 stream wrapper and unrelated PackageSpec/location work. Consolidate the runtime graph parser, avoid allocations for known property names, and reject malformed nested duplicate and null dependency data. Benchmarking the full .NET SDK runtime graph shows 21.6% lower parse time and 32.3% fewer allocations. Co-authored-by: Copilot App <[email protected]>
baronfel
force-pushed
the
baronfel-aot-runtime-graph-reader
branch
from
September 24, 2026 15:01
a82e2e8 to
f525b84
Compare
Use the path-only FileFormatException overload for invalid top-level package spec versions so the System.Text.Json reader path does not implicitly construct a Newtonsoft.Json JToken. Co-authored-by: Copilot App <[email protected]>
Contributor
Author
|
Ok, I've addressed the compatibility, performance, and maintainability notes that the last reviews left! The PR is much simpler now, thankfully. |
zivkan
approved these changes
Sep 24, 2026
Nigusu-Allehu
approved these changes
Sep 24, 2026
Contributor
|
This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 30 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch. |
Contributor
Author
|
Hi Mr Stale Bot! This PR has the merge in next release label, so we're just waiting on that to open up before merging. So it's not actually stale! |
3 tasks done
This was referenced Oct 7, 2026
This was referenced Oct 12, 2026
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.
Bug
Contributes to dotnet/sdk#55501
Description
This PR migrates runtime graph file and stream reading to System.Text.Json so the public runtime graph API works in trimming and NativeAOT scenarios.
The shipped
TextReaderoverload remains available as an obsolete Newtonsoft.Json compatibility path. The new reader parses each runtime graph incrementally and does not buffer the full document. The publicStreamoverload retains its ownership contract and disposes the supplied stream after parsing.The System.Text.Json path accepts UTF-8 input with or without a byte order mark. It preserves legacy scalar coercion, comments, trailing commas, and root-section last-value behavior. Malformed nested duplicate properties and null dependency versions are rejected instead of preserving Newtonsoft.Json's permissive behavior.
The parser uses allocation-free comparisons for known
runtimes,supports, and#importproperty names. It collects valid runtime graph entries directly instead of maintaining parallel lists and duplicate-property dictionaries.A BenchmarkDotNet comparison parsed the .NET SDK 10.0.303
RuntimeIdentifierGraph.jsonwith 100 in-process measurements:The simplified parser is 21.6% faster and allocates 32.3% less memory in this benchmark.
A separate follow-up commit changes one existing
JsonPackageSpecReadererror path to use the path-onlyFileFormatExceptionoverload. This prevents an implicitstring-to-JTokenconversion from retaining Newtonsoft.Json in the public System.Text.Json package-spec reader closure. Line information is not available for this semantic error becauseUtf8JsonReaderonly reports native line data when it throwsJsonException.Focused tests cover the runtime graph reader on .NET and .NET Framework. The NativeAOT test project roots the public API of each referenced NuGet assembly.
This is the first change in a planned series of focused System.Text.Json migrations, split for reviewability.
PR Checklist