Skip to content

perf: replace BufferPool Mutex with lock-free crossbeam ArrayQueue - #2923

Merged
oferchen merged 1 commit into
masterfrom
perf/buffer-pool-lock-free
Mar 22, 2026
Merged

oferchen merged 1 commit into
masterfrom
perf/buffer-pool-lock-free

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Replace Mutex<Vec<Vec>> in BufferPool with crossbeam_queue::ArrayQueue<Vec> for lock-free concurrent access
  • Eliminates mutex contention on hot paths: parallel_checksum.rs (rayon workers) and execute.rs (file transfer)
  • crossbeam-queue already proven in this codebase (crates/transfer/src/pipeline/spsc.rs)

Changes

  • ArrayQueue::new(max_buffers) replaces Mutex::new(Vec::with_capacity(max_buffers))
  • pop() returns None when empty - allocates a fresh buffer (same as before)
  • push() returns Err when full - drops excess buffer (same as before)
  • Removed max_buffers field - ArrayQueue::capacity() provides this
  • No mutex poisoning possible - removed all expect(buffer pool mutex poisoned) calls
  • Added crossbeam-queue = 0.3 to engine/Cargo.toml
  • Public API unchanged: acquire, acquire_from, acquire_adaptive_from, return_buffer, BufferGuard, BorrowedBufferGuard

Test plan

  • All existing buffer_pool unit tests pass (unchanged - same API semantics)
  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl
  • Concurrent access test (test_concurrent_access) validates lock-free correctness

Closes #1329

@oferchen
oferchen force-pushed the perf/buffer-pool-lock-free branch from e344bce to 2d9aa95 Compare March 22, 2026 06:55
Replace Mutex<Vec<Vec<u8>>> with crossbeam_queue::ArrayQueue for
lock-free concurrent buffer pool access. ArrayQueue uses CAS operations
instead of mutex locking, eliminating contention on hot paths in
parallel_checksum.rs (rayon workers) and execute.rs (file transfer).

- pop() returns None when empty (allocate fresh buffer)
- push() returns Err when full (drop excess buffer)
- No mutex poisoning possible
- crossbeam-queue already proven in crates/transfer/src/pipeline/spsc.rs

Closes #1329
@oferchen
oferchen force-pushed the perf/buffer-pool-lock-free branch from 2d9aa95 to d49f23a Compare March 22, 2026 08:08
@oferchen
oferchen merged commit ea74f2b into master Mar 22, 2026
9 checks passed
@oferchen
oferchen deleted the perf/buffer-pool-lock-free branch March 22, 2026 09:00
oferchen added a commit that referenced this pull request May 1, 2026
…2923)

Replace Mutex<Vec<Vec<u8>>> with crossbeam_queue::ArrayQueue for
lock-free concurrent buffer pool access. ArrayQueue uses CAS operations
instead of mutex locking, eliminating contention on hot paths in
parallel_checksum.rs (rayon workers) and execute.rs (file transfer).

- pop() returns None when empty (allocate fresh buffer)
- push() returns Err when full (drop excess buffer)
- No mutex poisoning possible
- crossbeam-queue already proven in crates/transfer/src/pipeline/spsc.rs

Closes #1329
oferchen added a commit that referenced this pull request May 5, 2026
…2923)

Replace Mutex<Vec<Vec<u8>>> with crossbeam_queue::ArrayQueue for
lock-free concurrent buffer pool access. ArrayQueue uses CAS operations
instead of mutex locking, eliminating contention on hot paths in
parallel_checksum.rs (rayon workers) and execute.rs (file transfer).

- pop() returns None when empty (allocate fresh buffer)
- push() returns Err when full (drop excess buffer)
- No mutex poisoning possible
- crossbeam-queue already proven in crates/transfer/src/pipeline/spsc.rs

Closes #1329
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