Skip to content

perf: replace flume with lock-free SPSC spin channel - #2349

Merged
oferchen merged 1 commit into
masterfrom
perf/spsc-spin-channel
Feb 19, 2026
Merged

oferchen merged 1 commit into
masterfrom
perf/spsc-spin-channel

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Replace flume channels with a custom SPSC channel backed by crossbeam_queue::ArrayQueue + AtomicBool disconnection flags + spin_loop() waiting — zero futex syscalls
  • Eliminate redundant zero-initialization in read_payload_into() (buffer.resize(len, 0) → unsafe set_len() before read overwrites)
  • Remove flume dependency, add crossbeam-queue (already in Cargo.lock via rayon)

Benchmark Results (10K files, 422MB, daemon loopback)

Metric Before (flume) After (SPSC) Change
futex syscalls 47,000 3 -99.99%
Total syscalls 136,156 88,192 -35%
Initial copy vs upstream 1.63x faster 1.69x faster +4%
Incremental vs upstream 1.82x faster 1.84x faster +1%

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
  • cargo nextest run --workspace --all-features — 21,733 tests pass
  • Functional alignment verified: 10K files, matching sizes
  • strace confirms futex elimination (47K → 3)
  • Hyperfine benchmarks vs upstream rsync and previous HEAD

Replace flume channels with a custom SPSC (single-producer,
single-consumer) channel backed by crossbeam_queue::ArrayQueue and
AtomicBool disconnection flags. Uses spin_loop() for waiting instead
of thread::park/unpark, eliminating all futex syscalls from the
network→disk thread pipeline.

Also eliminates redundant zero-initialization in read_payload_into()
by using unsafe set_len() instead of resize(len, 0) before the read
loop overwrites the same memory.

Results (10K files, 422MB, daemon loopback):
- futex: 47,000 → 3 (99.99% reduction)
- Total syscalls: 136K → 88K (35% reduction)
- Initial copy: 1.69x faster than upstream rsync
- Incremental: 1.84x faster than upstream rsync
@oferchen
oferchen merged commit 7b00961 into master Feb 19, 2026
28 of 30 checks passed
@oferchen
oferchen deleted the perf/spsc-spin-channel branch February 19, 2026 06:02
oferchen added a commit that referenced this pull request May 1, 2026
perf: replace flume with lock-free SPSC spin channel
oferchen added a commit that referenced this pull request May 5, 2026
perf: replace flume with lock-free SPSC spin channel
oferchen added a commit that referenced this pull request May 18, 2026
Add a criterion benchmark that sweeps the four SpillPolicy cells
(compression None vs Zstd-3, granularity WholeBatch vs PerItem)
against a forced-spill workload of 1000 mixed DeltaResult payloads,
plus a real SpillableReorderBuffer baseline with a 16 KiB threshold.

Each cell prints its simulated bytes-on-disk alongside the criterion
timing so default tuning has a side-by-side wall-clock + space view.
The bench is cfg(unix) and gated behind the existing spill-compression
feature, so default builds stay free of the zstd dev dependency.
oferchen added a commit that referenced this pull request May 18, 2026
Add a criterion benchmark that sweeps the four SpillPolicy cells
(compression None vs Zstd-3, granularity WholeBatch vs PerItem)
against a forced-spill workload of 1000 mixed DeltaResult payloads,
plus a real SpillableReorderBuffer baseline with a 16 KiB threshold.

Each cell prints its simulated bytes-on-disk alongside the criterion
timing so default tuning has a side-by-side wall-clock + space view.
The bench is cfg(unix) and gated behind the existing spill-compression
feature, so default builds stay free of the zstd dev dependency.
oferchen added a commit that referenced this pull request May 18, 2026
* bench(engine): SpillPolicy compression/granularity perf (#2349)

Add a criterion benchmark that sweeps the four SpillPolicy cells
(compression None vs Zstd-3, granularity WholeBatch vs PerItem)
against a forced-spill workload of 1000 mixed DeltaResult payloads,
plus a real SpillableReorderBuffer baseline with a 16 KiB threshold.

Each cell prints its simulated bytes-on-disk alongside the criterion
timing so default tuning has a side-by-side wall-clock + space view.
The bench is cfg(unix) and gated behind the existing spill-compression
feature, so default builds stay free of the zstd dev dependency.

* chore: refresh Cargo.lock
oferchen added a commit that referenced this pull request May 18, 2026
* bench(engine): SpillPolicy compression/granularity perf (#2349)

Add a criterion benchmark that sweeps the four SpillPolicy cells
(compression None vs Zstd-3, granularity WholeBatch vs PerItem)
against a forced-spill workload of 1000 mixed DeltaResult payloads,
plus a real SpillableReorderBuffer baseline with a 16 KiB threshold.

Each cell prints its simulated bytes-on-disk alongside the criterion
timing so default tuning has a side-by-side wall-clock + space view.
The bench is cfg(unix) and gated behind the existing spill-compression
feature, so default builds stay free of the zstd dev dependency.

* chore: refresh Cargo.lock
oferchen added a commit that referenced this pull request May 18, 2026
* bench(engine): SpillPolicy compression/granularity perf (#2349)

Add a criterion benchmark that sweeps the four SpillPolicy cells
(compression None vs Zstd-3, granularity WholeBatch vs PerItem)
against a forced-spill workload of 1000 mixed DeltaResult payloads,
plus a real SpillableReorderBuffer baseline with a 16 KiB threshold.

Each cell prints its simulated bytes-on-disk alongside the criterion
timing so default tuning has a side-by-side wall-clock + space view.
The bench is cfg(unix) and gated behind the existing spill-compression
feature, so default builds stay free of the zstd dev dependency.

* chore: refresh Cargo.lock
oferchen added a commit that referenced this pull request Aug 24, 2026
* bench(engine): SpillPolicy compression/granularity perf (#2349)

Add a criterion benchmark that sweeps the four SpillPolicy cells
(compression None vs Zstd-3, granularity WholeBatch vs PerItem)
against a forced-spill workload of 1000 mixed DeltaResult payloads,
plus a real SpillableReorderBuffer baseline with a 16 KiB threshold.

Each cell prints its simulated bytes-on-disk alongside the criterion
timing so default tuning has a side-by-side wall-clock + space view.
The bench is cfg(unix) and gated behind the existing spill-compression
feature, so default builds stay free of the zstd dev dependency.

* chore: refresh Cargo.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant