Skip to content

feat(engine): per-thread buffer slab BufferPool alternative (#1271, #1370) - #4286

Merged
oferchen merged 1 commit into
masterfrom
feat/per-thread-buffer-slab-1271
May 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/per-thread-buffer-slab-1271

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds opt-in per-thread LIFO buffer slab in front of BufferPool, gated behind the new thread-slab-pool cargo feature (default off, existing pool stays default).
  • Implements the design at docs/design/per-thread-buffer-slab.md (merged via docs(design): per-thread buffer slab for engine BufferPool (#1271, #1370) #4230): per-thread thread_local! Vec<Vec<u8>> with bounded slot count (default 8) and bounded byte cap (default 1 MiB), with the existing lock-free central queue demoted to a global overflow / balancer for cross-thread returns and donation of long-lived buffers.
  • Preserves BufferGuard / BorrowedBufferGuard Drop signatures byte-for-byte; the backend switch is a compile-time fork inside thread_local_cache.rs so pool.rs reads identically on both paths.
  • Adds periodic FIFO donation (every 64th return) that pushes the slab's oldest entry to the central queue to break "pinning" on idle threads, while LIFO acquire keeps the warmest buffer on the hot path.

Files

  • crates/engine/src/local_copy/buffer_pool/thread_slab.rs (new) - LocalSlab LIFO storage, slot / byte caps, FIFO donation, thread teardown drain hook, plus unit tests.
  • crates/engine/src/local_copy/buffer_pool/thread_local_cache.rs - feature-gated dispatch to either the single-slot path (default) or the slab path.
  • crates/engine/src/local_copy/buffer_pool/pool.rs - donation hook in return_buffer (cfg-gated, zero overhead when feature is off).
  • crates/engine/src/local_copy/buffer_pool/mod.rs - registers thread_slab module behind the feature.
  • crates/engine/src/local_copy/buffer_pool/tests.rs - integration tests for slab teardown, cross-thread return, bounded memory, periodic donation, LIFO ordering, multi-thread stress.
  • crates/engine/Cargo.toml - declares the thread-slab-pool feature.

Test plan

  • cargo nextest run -p engine --features thread-slab-pool (CI)
  • cargo nextest run -p engine (default, slab feature off) - existing single-slot path stays green
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings (CI)
  • cargo fmt --all -- --check (CI)

Adds an opt-in per-thread LIFO slab in front of BufferPool, gated behind
the new `thread-slab-pool` feature (default off). The slab keeps a
depth-bounded `Vec<Vec<u8>>` per thread with explicit slot and byte caps
(default 8 slots, 1 MiB), and falls through to the existing lock-free
central queue for cross-thread returns, overflow, and periodic donation
of long-lived buffers.

The public surface (BufferPool, BufferGuard, BorrowedBufferGuard Drop)
is unchanged - callers always go through `pool.return_buffer` and the
guard Drop signatures stay byte-for-byte identical. Switching between
the single-slot and slab backends happens at compile time inside
`thread_local_cache.rs`, so `pool.rs` reads the same on both paths.

Implements the design at docs/design/per-thread-buffer-slab.md merged
via #4230. Closes part of #1271 and #1370.
@oferchen
oferchen merged commit cdf9aa6 into master May 17, 2026
13 of 14 checks passed
@github-actions github-actions Bot added the enhancement New feature or request label May 17, 2026
oferchen added a commit that referenced this pull request May 18, 2026
Adds an opt-in per-thread LIFO slab in front of BufferPool, gated behind
the new `thread-slab-pool` feature (default off). The slab keeps a
depth-bounded `Vec<Vec<u8>>` per thread with explicit slot and byte caps
(default 8 slots, 1 MiB), and falls through to the existing lock-free
central queue for cross-thread returns, overflow, and periodic donation
of long-lived buffers.

The public surface (BufferPool, BufferGuard, BorrowedBufferGuard Drop)
is unchanged - callers always go through `pool.return_buffer` and the
guard Drop signatures stay byte-for-byte identical. Switching between
the single-slot and slab backends happens at compile time inside
`thread_local_cache.rs`, so `pool.rs` reads the same on both paths.

Implements the design at docs/design/per-thread-buffer-slab.md merged
via #4230. Closes part of #1271 and #1370.
oferchen added a commit that referenced this pull request May 18, 2026
Adds an opt-in per-thread LIFO slab in front of BufferPool, gated behind
the new `thread-slab-pool` feature (default off). The slab keeps a
depth-bounded `Vec<Vec<u8>>` per thread with explicit slot and byte caps
(default 8 slots, 1 MiB), and falls through to the existing lock-free
central queue for cross-thread returns, overflow, and periodic donation
of long-lived buffers.

The public surface (BufferPool, BufferGuard, BorrowedBufferGuard Drop)
is unchanged - callers always go through `pool.return_buffer` and the
guard Drop signatures stay byte-for-byte identical. Switching between
the single-slot and slab backends happens at compile time inside
`thread_local_cache.rs`, so `pool.rs` reads the same on both paths.

Implements the design at docs/design/per-thread-buffer-slab.md merged
via #4230. Closes part of #1271 and #1370.
@oferchen
oferchen deleted the feat/per-thread-buffer-slab-1271 branch May 19, 2026 19:28
oferchen added a commit that referenced this pull request Aug 24, 2026
Adds an opt-in per-thread LIFO slab in front of BufferPool, gated behind
the new `thread-slab-pool` feature (default off). The slab keeps a
depth-bounded `Vec<Vec<u8>>` per thread with explicit slot and byte caps
(default 8 slots, 1 MiB), and falls through to the existing lock-free
central queue for cross-thread returns, overflow, and periodic donation
of long-lived buffers.

The public surface (BufferPool, BufferGuard, BorrowedBufferGuard Drop)
is unchanged - callers always go through `pool.return_buffer` and the
guard Drop signatures stay byte-for-byte identical. Switching between
the single-slot and slab backends happens at compile time inside
`thread_local_cache.rs`, so `pool.rs` reads the same on both paths.

Implements the design at docs/design/per-thread-buffer-slab.md merged
via #4230. Closes part of #1271 and #1370.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant