Repository navigation
feat(engine): per-thread buffer slab BufferPool alternative (#1271, #1370) - #4286
Merged
Merged
Conversation
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
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BufferPool, gated behind the newthread-slab-poolcargo feature (default off, existing pool stays default).docs/design/per-thread-buffer-slab.md(merged via docs(design): per-thread buffer slab for engine BufferPool (#1271, #1370) #4230): per-threadthread_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.BufferGuard/BorrowedBufferGuardDrop signatures byte-for-byte; the backend switch is a compile-time fork insidethread_local_cache.rssopool.rsreads identically on both paths.Files
crates/engine/src/local_copy/buffer_pool/thread_slab.rs(new) -LocalSlabLIFO 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 inreturn_buffer(cfg-gated, zero overhead when feature is off).crates/engine/src/local_copy/buffer_pool/mod.rs- registersthread_slabmodule 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 thethread-slab-poolfeature.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 greencargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings(CI)cargo fmt --all -- --check(CI)