Repository navigation
Fix immutable sorted dictionary deserialization and simplify converter setup - #137036
Merged
eiriktsarpalis merged 2 commits intoNov 6, 2026
Merged
Conversation
Use a dedicated SortedDictionary-backed converter so immutable sorted dictionary deserialization preserves comparison-based key semantics without hash staging. Keep duplicate rejection comparer-based and preserve last-write-wins when duplicates are allowed. Consolidate reflection-only configuration hooks onto their converters and remove redundant WithReflection types. Add public comparer regressions and strict source-generated ILLink/NativeAOT coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
Moving reflection-only configuration off the WithReflection constructors removed the IL2026 warning sites in these factories. Their old suppressions now trigger IL2121 during the whole-framework linker build. Remove only the two unused suppressions; retain required reflection-dataflow suppression and reflection-hook annotations. Validated with the CI whole-framework linker target using warnings-as-errors and public collection/constructor tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
jeffhandley
approved these changes
Nov 6, 2026
eiriktsarpalis
deleted the
eiriktsarpalis-stj-collection-deserialization
branch
November 6, 2026 11:22
This was referenced Nov 6, 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.
Immutable sorted dictionary deserialization currently accumulates entries in a
Dictionary<TKey, TValue>before invoking the immutable factory. This applies equality/hash semantics before the destination's ordering comparer, which can collapse comparison-distinct keys or produce the wrong duplicate-key behavior. It also introduces hash-based accumulation for a comparison-based destination.Changes
ImmutableSortedDictionaryconverter backed bySortedDictionary<TKey, TValue>. Duplicate detection follows the destination key comparer: allowed duplicates remain last-write-wins; disallowed duplicates throwJsonException, including when the values are equal.WithReflectionsubclasses. Source-generated metadata continues to supply constructor/add delegates directly; reflection setup retains its method-level trimming and dynamic-code annotations.Validation
All validation used Windows x64 and the repository's Release runtime/library builds.
.\build.cmd clr+libs -rc Release -lc Release.\dotnet.cmd build .\src\libraries\System.Text.Json\src\System.Text.Json.csproj -c Release -p:RuntimeConfiguration=ReleaseEvery linker/AOT app returned 100, with no linker/AOT diagnostics. The comparer regressions were also demonstrated failing against the original implementation before applying the fix. Non-Windows execution was not performed.
Performance tradeoff
Tree buffering fixes comparison semantics and removes serializer-introduced key hashing, but adds comparison work. BenchmarkDotNet measurements of the dedicated sorted-converter implementation, before the final reflection-hook-only consolidation, showed the following for 1,024 entries with duplicates allowed:
The string-key case was approximately 70% slower. This is a correctness/hash-resilience change, not a throughput optimization. The final reflection-only consolidation does not change allocation or insertion logic, but those measurements were not rerun after that cleanup. The changed duplicate-key treatment and exception type are observable behavioral corrections.
Note
This pull request was authored with GitHub Copilot.