Use streaming serialization for JSONL entries - #134554
Merged
Merged
Conversation
Serialize each JSONL value through the async streaming pipeline so large and nested async values honor backpressure and cancellation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2d9038d0-a532-4707-8446-e46cbbf53858
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 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 |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One or more issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (3)
What changed in this PR
Updates JSONL serialization to use the asynchronous streaming serializer while preserving writer ownership and backpressure.
Changes:
- Reuses a caller-provided
Utf8JsonWriterand returnsFlushResult. - Adds streaming, cancellation, failure, polymorphism, and source-generation coverage.
- Supports JSONL elements that are themselves async enumerables.
| File | Description |
|---|---|
| src/libraries/System.Text.Json/tests/Common/AsyncEnumerableTests.cs | Updated as part of this pull request. |
| src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.WriteHelpers.cs | Updated as part of this pull request. |
| src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs | Updated as part of this pull request. |
| src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs | Updated as part of this pull request. |
| src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Pipe.cs | Updated as part of this pull request. |
jozkee
approved these changes
Sep 24, 2026
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
4 tasks
artl93
pushed a commit
that referenced
this pull request
Sep 25, 2026
Backport of #134554 to release/11.0 /cc @eiriktsarpalis ## Customer Impact - [x] Customer reported - [ ] Found internally The newly introduced `JsonSerializer.SerializeAsyncEnumerable` methods were using non-streaming serialization instead of streaming serialization when handling individual JSONL elements. This resulted in the following issues: * Excessive buffering when streaming large elements * Types requiring async serialization (such as nested IAsyncEnumerable data) were not supported in these methods. ## Regression - [ ] Yes - [x] No ## Testing Added relevant testing covering the impacted scenaria. ## Risk Low. Makes a straightforward change to product code so that the streaming serialization is used instead. Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com> Copilot-Session: 2d9038d0-a532-4707-8446-e46cbbf53858
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.


The newly introduced JSONL serialization APIs weren't using streaming serialization when serializing individual elements. This changes fixes that issue. Should be backported to .NET 11.