Skip to content

perf(mpsc): reduce intermediate copies in bounded receives - #407

Open
sanjay7178 wants to merge 4 commits into
apache:mainfrom
sanjay7178:fix-mpsc
Open

sanjay7178 wants to merge 4 commits into
apache:mainfrom
sanjay7178:fix-mpsc

Conversation

@sanjay7178

@sanjay7178 sanjay7178 commented Nov 4, 2026 •

Copy link
Copy Markdown

Summary

Reduce intermediate payload copies in bounded MPSC receives by removing the payload/waker tuple from the receive path. Add matched inline and boxed benchmarks and ownership tests for cancellation, disconnection, and resumed sends.

A balanced four-variant benchmark on Linux x86-64 measured the retained receive-only change at 230.5 ms versus 250.5 ms for the inline ready case (16 samples per variant). Contended inline medians were 730 versus 747 ms with broadly overlapping ranges; this does not establish a significant contended throughput improvement. The send-side change has been removed following review. Full methodology and raw samples are in the benchmark follow-up comment.

Related to #401; further work is needed to close the larger throughput gap.

Validation

  • Targeted large-payload ownership test and all 40 MPSC integration tests.
  • cargo x lint.
  • Baseline, send-only, receive-only, and combined benchmark variants with identical fixtures, fixed rounds, and balanced rotating run order.

Signed-off-by: sanjay7178 <saisanjay7660@gmail.com>
@sanjay7178 sanjay7178 changed the title Improve bounded MPSC throughput for inline 1 KiB messages feat(perf) : Improve bounded MPSC throughput for inline 1 KiB messages Nov 4, 2026
@sanjay7178
sanjay7178 marked this pull request as ready for review November 5, 2026 06:15
@orthur2
orthur2 self-requested a review November 8, 2026 02:54

@orthur2 orthur2 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.

Thanks for working on this. The receive-side change looks good to me, but I'd drop the send-side part.

Comment thread asyncband/src/mpsc/bounded/sender.rs Resolved
@sanjay7178

Copy link
Copy Markdown
Author

Benchmark follow-up

Removed the send hunk as requested; the implementation change now only simplifies receive result handling. The earlier combined before/after measurements did not establish the cause of the contended timing change.

Measured on Linux x86-64 (AMD EPYC-Rome VM, 16 CPUs), rustc 1.99.1 / LLVM 23.1.1, optimized Cargo bench builds. All four variants use base 452d858 plus identical PR benchmark fixtures. Baseline has neither hunk; send-only and receive-only isolate each hunk; combined has both. All builds completed before measurement; no tests or builds ran concurrently. Each case has one warmup per variant followed by 16 recorded launches per variant, rotating and reversing order in balanced blocks. Each launch uses --baseline-only --repeat 1 --raw. No outliers were removed.

Each cell is median ms (min–max); lower is faster.

Scenario Fixed rounds Baseline Send only Receive only (retained) Combined
ready-roundtrip-inline1k 1,000,000 250.5 (242–283) 264 (245–285) 230.5 (219–243) 243 (228–270)
tasks-4p1c-cap64-4w-inline1k 26 747 (634–832) 793 (712–873) 730 (581–837) 793 (557–877)
tasks-4p1c-cap64-4w 26 84 (74–92) 82.5 (74–91) 81 (77–92) 81 (72–87)

The isolated ready case supports dropping the send change on this host. Contended timings remain noisy and platform-dependent; these data do not establish a lock-timing mechanism or resolve #401. The usize filter also matches the inline and boxed rows: those extra rows were executed consistently for every variant, and the table selects only the exact usize row.

Raw recorded times in chronological order within each variant (ms)
ready-roundtrip-inline1k / baseline: [266, 250, 255, 251, 245, 260, 283, 246, 246, 243, 263, 253, 254, 247, 242, 243]
ready-roundtrip-inline1k / send: [251, 264, 245, 272, 260, 269, 285, 272, 254, 264, 269, 256, 260, 267, 260, 270]
ready-roundtrip-inline1k / receive: [243, 243, 223, 230, 242, 234, 239, 219, 241, 227, 227, 231, 227, 229, 234, 221]
ready-roundtrip-inline1k / combined: [228, 260, 248, 230, 241, 245, 254, 270, 236, 248, 231, 247, 246, 238, 228, 231]
tasks-4p1c-cap64-4w-inline1k / baseline: [777, 667, 643, 634, 801, 769, 697, 762, 832, 807, 722, 829, 769, 693, 732, 729]
tasks-4p1c-cap64-4w-inline1k / send: [871, 768, 754, 840, 712, 873, 771, 725, 822, 818, 825, 802, 757, 784, 780, 833]
tasks-4p1c-cap64-4w-inline1k / receive: [704, 690, 581, 751, 601, 810, 778, 759, 632, 744, 699, 818, 716, 630, 837, 819]
tasks-4p1c-cap64-4w-inline1k / combined: [557, 752, 585, 793, 793, 824, 871, 844, 842, 818, 779, 688, 812, 780, 877, 705]
tasks-4p1c-cap64-4w / baseline: [80, 81, 82, 92, 85, 85, 86, 81, 84, 74, 89, 89, 88, 84, 80, 84]
tasks-4p1c-cap64-4w / send: [88, 85, 91, 74, 75, 82, 82, 80, 77, 78, 83, 84, 80, 86, 84, 83]
tasks-4p1c-cap64-4w / receive: [81, 92, 77, 86, 81, 81, 84, 86, 83, 81, 79, 81, 81, 78, 81, 82]
tasks-4p1c-cap64-4w / combined: [82, 81, 72, 82, 79, 87, 85, 81, 77, 74, 78, 82, 83, 81, 79, 76]

@sanjay7178 sanjay7178 changed the title feat(perf) : Improve bounded MPSC throughput for inline 1 KiB messages perf(mpsc): reduce intermediate copies in bounded receives Nov 8, 2026

This branch has not been deployed

No deployments
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.

2 participants