Skip to content

Use streaming serialization for JSONL entries - #134554

Merged
eiriktsarpalis merged 1 commit into
dotnet:mainfrom
eiriktsarpalis:fix/jsonl-flushing
Sep 24, 2026
Merged

eiriktsarpalis merged 1 commit into
dotnet:mainfrom
eiriktsarpalis:fix/jsonl-flushing

Conversation

@eiriktsarpalis

@eiriktsarpalis eiriktsarpalis commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

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.

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
Copilot AI lite review requested due to automatic review settings September 23, 2026 21:03
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 1 Medium severity

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 Utf8JsonWriter and returns FlushResult.
  • 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.

@eiriktsarpalis
eiriktsarpalis merged commit 99f3a67 into dotnet:main Sep 24, 2026
87 checks passed
@eiriktsarpalis
eiriktsarpalis deleted the fix/jsonl-flushing branch September 24, 2026 15:32
@eiriktsarpalis

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 25, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants