-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Json] Avoid ReadOnlySequence with Stream deserializing #118408
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes JSON deserialization from streams by eliminating redundant ReadOnlySequence creation and conditional checks when constructing Utf8JsonReader instances. The change aims to address performance regressions noted in issue #118173.
Key changes:
- Refactors reader creation logic into specialized methods on buffer state classes
- Eliminates duplicate conditional logic for single vs multi-segment sequences
- Simplifies the deserialization path by centralizing reader instantiation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| IReadBufferState.cs | Adds abstract GetReader method to the interface |
| StreamReadBufferState.cs | Implements GetReader for stream-based buffering |
| PipeReadBufferState.cs | Implements GetReader with single/multi-segment optimization |
| JsonTypeInfoOfT.ReadHelper.cs | Replaces inline reader creation with GetReader call |
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/IReadBufferState.cs
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
|
@EgorBot -windows_intel --filter "*System.Text.Json.Serialization.Tests.ReadJson<*FromStream" |
Removes the construction of a
ReadOnlySequenceandifchecks for creating aUtf8JsonReaderin theStreamcase. Might fix the regressions shown in #118173 (comment).I say might because locally running the microbenchmarks didn't give the most consistent results, but over a bunch of runs the general trend was that this change improved things.