Skip to content

Remove per-message Task.Run from Service Bus deserialization - #1379

Open
berndverst wants to merge 1 commit into
mainfrom
berndverst-issue-1376-inline-message-stream
Open

Remove per-message Task.Run from Service Bus deserialization#1379
berndverst wants to merge 1 commit into
mainfrom
berndverst-issue-1376-inline-message-stream

Conversation

@berndverst

Copy link
Copy Markdown
Member

Summary

  • return an already-completed Task<Stream> for inline Service Bus message bodies on both netstandard2.0 and net48
  • preserve the existing MemoryStream / GetBody<Stream>() behavior and leave external blob-store loading asynchronous
  • add focused cross-target tests for compressed and uncompressed round trips, observable synchronous completion, and external stream ownership

Compatibility and performance

The private Task<Stream> contract is unchanged, as are the inline stream contents, initial position, and disposal lifetime. The blob-backed branch still returns LoadStreamAsync directly. Inline messages no longer allocate and queue a Task.Run work item, avoiding per-message thread-pool scheduling and batch bursts at the default prefetch size.

Tests

  • dotnet test Test\DurableTask.ServiceBus.Tests\DurableTask.ServiceBus.Tests.csproj -f net8.0 --filter "FullyQualifiedName~ServiceBusUtilsTests"
  • dotnet test Test\DurableTask.ServiceBus.Tests\DurableTask.ServiceBus.Tests.csproj -f net48 --filter "FullyQualifiedName~ServiceBusUtilsTests"

Fixes #1376

Return completed stream tasks for inline message bodies while retaining asynchronous blob-store loading. Add cross-target coverage for round trips, synchronous completion, and stream ownership.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1347830a-17c5-4248-8e41-fee30d3066b4
Copilot AI review requested due to automatic review settings July 27, 2026 20:36
message.UserProperties[FrameworkConstants.CompressionTypePropertyName] =
FrameworkConstants.CompressionTypeNonePropertyValue;

var stream = new MemoryStream();

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.

Pull request overview

This PR removes per-message Task.Run scheduling from inline Service Bus message stream loading by returning already-completed Task<Stream> instances, reducing thread-pool work-item bursts during batch deserialization.

Changes:

  • Replace Task.Run(...) with Task.FromResult(...) for inline message bodies in ServiceBusUtils.LoadMessageStreamAsync (both NETSTANDARD2_0 and net48 branches).
  • Add new unit tests intended to validate inline (compressed/uncompressed) round trips, synchronous completion for uncompressed inline messages, and async blob-store behavior/stream ownership for external messages.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/DurableTask.ServiceBus/Common/ServiceBusUtils.cs Removes thread-pool hop for inline message-body stream creation by returning completed tasks.
Test/DurableTask.ServiceBus.Tests/ServiceBusUtilsTests.cs Adds tests for inline/external deserialization behaviors, but currently placed in a directory not used by the active test project.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +18
namespace DurableTask.ServiceBus.Tests
{
using System;
using System.IO;
using System.Threading.Tasks;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove per-message Task.Run from Service Bus inline message deserialization

2 participants