Skip to content

Conversation

@BrennanConroy
Copy link
Member

Removes the construction of a ReadOnlySequence and if checks for creating a Utf8JsonReader in the Stream case. 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.

Copy link
Contributor

Copilot AI left a 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

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@PranavSenthilnathan
Copy link
Member

@EgorBot -windows_intel --filter "*System.Text.Json.Serialization.Tests.ReadJson<*FromStream"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants