Repository navigation
perf(serialization): read contiguous JSON payloads directly - #11270
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review comments remain, and focused coverage supports the changes.
Review tier: Lite
Findings: None
What changed in this PR
Optimizes JSON deserialization by reading contiguous payloads directly while preserving segmented and stream fallbacks.
Changes:
- Added direct contiguous-span parsing.
- Expanded coverage for input shapes, options, references, JSON nodes, and buffer overlap.
| File | Summary |
|---|---|
test/Orleans.Serialization.UnitTests/JsonCodecTests.cs |
Verifies supported input formats and options. |
src/Orleans.Serialization.SystemTextJson/JsonCodec.cs |
Parses contiguous JSON payloads directly. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code coverage
Report-only conclusion: current-main baseline stale. The newest successful coverage run tested 3604a08, not current main 9222be9. Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities. The comparison remains report-only while normal line and branch variance is calibrated. Coverage details |
Problem
JsonCodec.ReadValuestages every JSON payload in aPooledBufferbefore deserializing it, even when the reader already exposes the complete payload as a contiguous span. That adds a payload-sized copy and pooled-buffer operations on each non-reference read.Solution
Use
Reader.TryReadBytesto initializeUtf8JsonReaderdirectly over contiguous input. Continue using the existing pooled sequence path for payloads spanning segments and for stream input. Both paths share JSON reader/serializer options, nativeJsonNodehandling, and reference bookkeeping.The change follows the existing direct-read pattern in
StringCodec. Its benefit scales with payload size while keeping the wire format and public API stable. Focused coverage checks all input shapes, options, reference identity, native JSON nodes, and that contiguous JSON tokens overlap the original input buffer. No throughput claim is made without workload measurements.Microsoft Reviewers: Open in CodeFlow