Skip to content

bench(transfer): stdlib mpsc vs crossbeam channel overhead at 100K items (#1592) - #4203

Merged
oferchen merged 1 commit into
masterfrom
bench/sync-channel-overhead-1592
May 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
bench/sync-channel-overhead-1592

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add crates/transfer/benches/sync_channel_overhead.rs measuring per-item send+recv cost for std::sync::mpsc::channel, crossbeam_channel::unbounded, and crossbeam_channel::bounded(1024).
  • Sweeps payload sizes {32 B, 256 B, 4 KB} and thread shapes {1S+1R, 4S+1R, 1S+4R, 4S+4R} at 100K items, reporting throughput as Throughput::Elements(100_000) (items/sec).
  • Payloads pre-allocated outside the timed section; both producer and consumer threads drain to completion before sample ends. Pure userspace - no I/O, runs on Linux, macOS, Windows.

Why

The transfer pipeline uses a mix of stdlib mpsc and crossbeam_channel (both unbounded and bounded). This bench produces the evidence needed to decide whether to standardise on one channel kind (#1681) or to drop crossbeam_channel in low-fan-out sites where stdlib mpsc is at parity (#1370). The bounded vs unbounded delta also sets the threshold at which back-pressure becomes measurable on a hot path.

Test plan

  • cargo bench -p transfer -- sync_channel_overhead produces criterion rows for every payload / thread-shape / channel-kind combination.
  • No production code touched; cargo build and cargo clippy clean on the workspace.
  • cargo fmt --all -- --check passes.

Refs #1592 #1681 #1370

Add a criterion bench that compares per-item send+recv cost across
`std::sync::mpsc::channel`, `crossbeam_channel::unbounded`, and
`crossbeam_channel::bounded(1024)` at 100K items. Sweeps payload sizes
{32 B, 256 B, 4 KB} and thread shapes {1S+1R, 4S+1R, 1S+4R, 4S+4R} to
expose the contention regimes that appear in the engine and receiver
pipelines. Payloads are pre-allocated outside the timed section so the
measurement isolates channel cost from allocation. Throughput is
reported via `Throughput::Elements(100_000)` so the criterion summary
gives items/sec directly.

Pure userspace synchronisation - no I/O, no platform-specific paths,
runs identically on Linux, macOS, and Windows.

Refs #1592 #1681 #1370
@oferchen
oferchen merged commit 0e02fc2 into master May 17, 2026
40 checks passed
@oferchen
oferchen deleted the bench/sync-channel-overhead-1592 branch May 17, 2026 08:13
oferchen added a commit that referenced this pull request May 17, 2026
…#4212)

Document the four CAPACITY_MULTIPLIER sites and the two duplicate
hard-coded `2`s in delta_pipeline.rs, justify each against the recent
dispatch benches (#4203 channel overhead, #4204 reorder memory, #4206
dispatch decomposition, #4209 sp vs mp), and recommend keeping the
default at 2 with one follow-up bench specified to challenge it.
oferchen added a commit that referenced this pull request May 17, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request May 17, 2026
…1572) (#4209)

Adds `crates/engine/benches/sp_vs_mp_workqueue.rs` with two Criterion
groups that both move 100K items through the concurrent delta work
queue:

- `sp/1p/100k`: one producer thread pushes 100K pre-allocated DeltaWork
  items via the default-build `Send + !Clone` WorkQueueSender path.
- `mp/4p/100k`: four producer threads each push 25K pre-allocated items
  via the gated `Clone` impl on WorkQueueSender. Compiled only when
  `--features multi-producer` is set.

Both groups report `Throughput::Elements(100_000)` so items/sec figures
compare directly regardless of how the work is split. Inputs are
pre-allocated outside the timed section via `iter_batched`, matching
the discipline used by the parallel_dispatch_overhead bench.

The MP group is feature-gated behind the engine crate's existing
`multi-producer` feature - no Cargo.toml dependency change is required;
the gate already exists at `crates/engine/Cargo.toml:91`. The top-of-
file documentation cross-references the audit at
`docs/audits/workqueue-sender-multi-producer-audit.md` (PR #4173),
#4203 sync_channel bench, and #4206 parallel_dispatch_overhead bench,
and spells out the decision criteria (>=15% SP-vs-MP delta) that this
bench informs.
oferchen added a commit that referenced this pull request May 17, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 17, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 17, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 18, 2026
…ems (#4203)

Add a criterion bench that compares per-item send+recv cost across
`std::sync::mpsc::channel`, `crossbeam_channel::unbounded`, and
`crossbeam_channel::bounded(1024)` at 100K items. Sweeps payload sizes
{32 B, 256 B, 4 KB} and thread shapes {1S+1R, 4S+1R, 1S+4R, 4S+4R} to
expose the contention regimes that appear in the engine and receiver
pipelines. Payloads are pre-allocated outside the timed section so the
measurement isolates channel cost from allocation. Throughput is
reported via `Throughput::Elements(100_000)` so the criterion summary
gives items/sec directly.

Pure userspace synchronisation - no I/O, no platform-specific paths,
runs identically on Linux, macOS, and Windows.

Refs #1592 #1681 #1370
oferchen added a commit that referenced this pull request May 18, 2026
…#4212)

Document the four CAPACITY_MULTIPLIER sites and the two duplicate
hard-coded `2`s in delta_pipeline.rs, justify each against the recent
dispatch benches (#4203 channel overhead, #4204 reorder memory, #4206
dispatch decomposition, #4209 sp vs mp), and recommend keeping the
default at 2 with one follow-up bench specified to challenge it.
oferchen added a commit that referenced this pull request May 18, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request May 18, 2026
…1572) (#4209)

Adds `crates/engine/benches/sp_vs_mp_workqueue.rs` with two Criterion
groups that both move 100K items through the concurrent delta work
queue:

- `sp/1p/100k`: one producer thread pushes 100K pre-allocated DeltaWork
  items via the default-build `Send + !Clone` WorkQueueSender path.
- `mp/4p/100k`: four producer threads each push 25K pre-allocated items
  via the gated `Clone` impl on WorkQueueSender. Compiled only when
  `--features multi-producer` is set.

Both groups report `Throughput::Elements(100_000)` so items/sec figures
compare directly regardless of how the work is split. Inputs are
pre-allocated outside the timed section via `iter_batched`, matching
the discipline used by the parallel_dispatch_overhead bench.

The MP group is feature-gated behind the engine crate's existing
`multi-producer` feature - no Cargo.toml dependency change is required;
the gate already exists at `crates/engine/Cargo.toml:91`. The top-of-
file documentation cross-references the audit at
`docs/audits/workqueue-sender-multi-producer-audit.md` (PR #4173),
#4203 sync_channel bench, and #4206 parallel_dispatch_overhead bench,
and spells out the decision criteria (>=15% SP-vs-MP delta) that this
bench informs.
oferchen added a commit that referenced this pull request May 18, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 18, 2026
…ems (#4203)

Add a criterion bench that compares per-item send+recv cost across
`std::sync::mpsc::channel`, `crossbeam_channel::unbounded`, and
`crossbeam_channel::bounded(1024)` at 100K items. Sweeps payload sizes
{32 B, 256 B, 4 KB} and thread shapes {1S+1R, 4S+1R, 1S+4R, 4S+4R} to
expose the contention regimes that appear in the engine and receiver
pipelines. Payloads are pre-allocated outside the timed section so the
measurement isolates channel cost from allocation. Throughput is
reported via `Throughput::Elements(100_000)` so the criterion summary
gives items/sec directly.

Pure userspace synchronisation - no I/O, no platform-specific paths,
runs identically on Linux, macOS, and Windows.

Refs #1592 #1681 #1370
oferchen added a commit that referenced this pull request May 18, 2026
…#4212)

Document the four CAPACITY_MULTIPLIER sites and the two duplicate
hard-coded `2`s in delta_pipeline.rs, justify each against the recent
dispatch benches (#4203 channel overhead, #4204 reorder memory, #4206
dispatch decomposition, #4209 sp vs mp), and recommend keeping the
default at 2 with one follow-up bench specified to challenge it.
oferchen added a commit that referenced this pull request May 18, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request May 18, 2026
…1572) (#4209)

Adds `crates/engine/benches/sp_vs_mp_workqueue.rs` with two Criterion
groups that both move 100K items through the concurrent delta work
queue:

- `sp/1p/100k`: one producer thread pushes 100K pre-allocated DeltaWork
  items via the default-build `Send + !Clone` WorkQueueSender path.
- `mp/4p/100k`: four producer threads each push 25K pre-allocated items
  via the gated `Clone` impl on WorkQueueSender. Compiled only when
  `--features multi-producer` is set.

Both groups report `Throughput::Elements(100_000)` so items/sec figures
compare directly regardless of how the work is split. Inputs are
pre-allocated outside the timed section via `iter_batched`, matching
the discipline used by the parallel_dispatch_overhead bench.

The MP group is feature-gated behind the engine crate's existing
`multi-producer` feature - no Cargo.toml dependency change is required;
the gate already exists at `crates/engine/Cargo.toml:91`. The top-of-
file documentation cross-references the audit at
`docs/audits/workqueue-sender-multi-producer-audit.md` (PR #4173),
#4203 sync_channel bench, and #4206 parallel_dispatch_overhead bench,
and spells out the decision criteria (>=15% SP-vs-MP delta) that this
bench informs.
oferchen added a commit that referenced this pull request May 18, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request Aug 24, 2026
…ems (#4203)

Add a criterion bench that compares per-item send+recv cost across
`std::sync::mpsc::channel`, `crossbeam_channel::unbounded`, and
`crossbeam_channel::bounded(1024)` at 100K items. Sweeps payload sizes
{32 B, 256 B, 4 KB} and thread shapes {1S+1R, 4S+1R, 1S+4R, 4S+4R} to
expose the contention regimes that appear in the engine and receiver
pipelines. Payloads are pre-allocated outside the timed section so the
measurement isolates channel cost from allocation. Throughput is
reported via `Throughput::Elements(100_000)` so the criterion summary
gives items/sec directly.

Pure userspace synchronisation - no I/O, no platform-specific paths,
runs identically on Linux, macOS, and Windows.

Refs #1592 #1681 #1370
oferchen added a commit that referenced this pull request Aug 24, 2026
…#4212)

Document the four CAPACITY_MULTIPLIER sites and the two duplicate
hard-coded `2`s in delta_pipeline.rs, justify each against the recent
dispatch benches (#4203 channel overhead, #4204 reorder memory, #4206
dispatch decomposition, #4209 sp vs mp), and recommend keeping the
default at 2 with one follow-up bench specified to challenge it.
oferchen added a commit that referenced this pull request Aug 24, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request Aug 24, 2026
…1572) (#4209)

Adds `crates/engine/benches/sp_vs_mp_workqueue.rs` with two Criterion
groups that both move 100K items through the concurrent delta work
queue:

- `sp/1p/100k`: one producer thread pushes 100K pre-allocated DeltaWork
  items via the default-build `Send + !Clone` WorkQueueSender path.
- `mp/4p/100k`: four producer threads each push 25K pre-allocated items
  via the gated `Clone` impl on WorkQueueSender. Compiled only when
  `--features multi-producer` is set.

Both groups report `Throughput::Elements(100_000)` so items/sec figures
compare directly regardless of how the work is split. Inputs are
pre-allocated outside the timed section via `iter_batched`, matching
the discipline used by the parallel_dispatch_overhead bench.

The MP group is feature-gated behind the engine crate's existing
`multi-producer` feature - no Cargo.toml dependency change is required;
the gate already exists at `crates/engine/Cargo.toml:91`. The top-of-
file documentation cross-references the audit at
`docs/audits/workqueue-sender-multi-producer-audit.md` (PR #4173),
#4203 sync_channel bench, and #4206 parallel_dispatch_overhead bench,
and spells out the decision criteria (>=15% SP-vs-MP delta) that this
bench informs.
oferchen added a commit that referenced this pull request Aug 24, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
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.

1 participant