Avoid serializing inline Azure Storage queue messages twice - #1380
Bernd Verst (berndverst) wants to merge 5 commits into
Conversation
Reuse the MessageData JSON already produced for size selection when the payload remains inline. Add exact wire-equivalence and threshold-path regression coverage for both serialization modes and a custom binder. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9509e194-db0b-4024-b7b0-26481278e0db
Verify exact inline payload equivalence, single-pass custom binder behavior, and the inline/blob boundary for both data-contract serialization modes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9509e194-db0b-4024-b7b0-26481278e0db
There was a problem hiding this comment.
Pull request overview
This PR removes a redundant JSON serialization on the common inline-queue-message path in MessageManager.SerializeMessageDataAsync, reusing the already-produced JSON payload that was generated for the UTF-8 size check. It adds regression tests to assert byte-for-byte equivalence with the prior “serialize twice” behavior (including custom type binder behavior and both UseDataContractSerialization modes), and to validate behavior at the exact 45 KiB inline threshold and just above it (blob offload + wrapper).
Changes:
- Reuse the initial
rawContentJSON string for inline queue payloads instead of serializingMessageDataa second time. - Add tests validating inline payload equivalence (including custom binder behavior) in both
UseDataContractSerializationmodes. - Add boundary tests covering the exact 45 KiB inline cutoff and the above-threshold blob-wrapper path (including verifying stored blob content).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/DurableTask.AzureStorage/MessageManager.cs | Avoids duplicate serialization by returning the already-generated rawContent for inline messages. |
| test/DurableTask.AzureStorage.Tests/MessageManagerTests.cs | Adds regression coverage for inline payload equivalence and for inline/blob behavior at and above the 45 KiB threshold. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, preserves the payload format, and is backed by targeted tests covering both serializer modes and the inline/blob threshold boundary.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The custom binder test helper does not compile for net8.0/net48 and needs the target-appropriate binder implementation.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Summary
MessageDataJSON already produced for the UTF-8 size check when a queue message stays inlineUseDataContractSerializationmodesBackward compatibility
The initial serialization already determines both the queue payload size and the inline/blob decision.
TotalMessageSizeBytesis internal and is not a data member. For stable messages with deterministic, side-effect-free serialization, returning that existing JSON on the inline path is byte-for-byte equivalent to the previous second serialization. The size threshold, serializer configuration, public API signatures, queue schema, blob upload content, and blob-reference wrapper serialization are unchanged.Serialization invocation counts are implementation details, not an API contract. Inline messages now undergo one full serialization pass instead of two. Custom
ICustomTypeBinder.BindToNameimplementations, getters, or serialization callbacks on transport types that change their output or rely on side effects across passes can observe a behavior change and should be reviewed when upgrading. The existing blob path already serializes the full message only once, followed by a separate serialization of the blob-reference wrapper. These expectations are documented in the Azure Storage provider guide and custom type-binder API documentation.Testing
dotnet test Test\DurableTask.AzureStorage.Tests\DurableTask.AzureStorage.Tests.csproj --framework net8.0 --filter "FullyQualifiedName~DurableTask.AzureStorage.Tests.MessageManagerTests"dotnet test Test\DurableTask.AzureStorage.Tests\DurableTask.AzureStorage.Tests.csproj --framework net48 --filter "FullyQualifiedName~DurableTask.AzureStorage.Tests.MessageManagerTests"net8.0andnet48after the documentation update to verify the test helper's binder assignment; both serializer modes passed on both targets.Fixes #1378