Skip to content

perf(liburing): add criterion 0.8.2 benches, hierarchical state machines, and hot-path optimizations - #17

Merged
trunkszi merged 1 commit into
mainfrom
perf/criterion-hsm-hotpath
Oct 27, 2026
Merged

trunkszi merged 1 commit into
mainfrom
perf/criterion-hsm-hotpath

Conversation

@trunkszi

Copy link
Copy Markdown
Owner

Summary

Add a Criterion 0.8.2 hot-path benchmark suite with zero-allocation pre-flight gates across liburing-rs, refactor OperationSlab and CompletionSocketTable slot state into compact #[repr(u8)] Hierarchical State Machines (OperationPhase and SocketSlotPhase), and pack OperationSlab slot metadata to improve submission and completion hot-path latency.

Cargo.toml                                     |   1 +
Cargo.lock                                     | 392 +++++++++++++++++++++++++
crates/liburing/
├── Cargo.toml                                 |   5 +
├── benches/uring_hotpath_bench.rs             | 366 +++++++++++++++++++++++ (new)
└── src/
    ├── fixed_buffers.rs                       |  11 +-
    ├── identity_map.rs                        |  42 ++-
    ├── operation_slab.rs                      | 311 ++++++++++++++------
    └── socket_io.rs                           |  42 ++-
  • Criterion 0.8.2 Benchmark Suite & Zero-Alloc Pre-Flight:
    • Register criterion = { version = "0.8.2", default-features = false, features = ["cargo_bench_support"] } in root [workspace.dependencies] and inherit via criterion = { workspace = true } in crates/liburing/Cargo.toml, with bench = false under [lib].
    • Add crates/liburing/benches/uring_hotpath_bench.rs covering single-shot, multishot, zero-copy, and cancellation OperationSlab lifecycles, OperationId payload bit-packing, FixedBufferRegistry lease/release, FixedFileSet lease/release, CompletionSocketTable close transitions, and real kernel io_uring NOP submit/wait dispatch, with a CountingAllocator zero-allocation pre-flight check outside the timed b.iter() loop.
  • Hierarchical State Machines (#[repr(u8)]) & Slot Packing:
    • Replace the 4-state OperationState + 3 sidecar booleans (multishot, zero_copy, zero_copy_notified) in crates/liburing/src/operation_slab.rs with a single 1-byte #[repr(u8)] OperationPhase whose low 2 bits encode OperationState directly (state() is a single bitmask + projection, size_of::<OperationPhase>() == 1).
    • Pack the free-list index into a u32 alongside generation: u32 in #[repr(C)] struct Slot<Meta> and flatten steady-state completion, cancellation, and zero-copy notification transitions.
    • Introduce 1-byte #[repr(u8)] SocketSlotPhase (Closed, Active, ClosingPending, size_of::<SocketSlotPhase>() == 1) in crates/liburing/src/socket_io.rs.
    • Add an IdentityMap linear-scan fast path for small tables (<= 8 entries) in crates/liburing/src/identity_map.rs while keeping IdentityMap crate-private (pub(crate)).

Evidence

Before vs. After Criterion Benchmarks (origin/main @ 8155225 vs. Branch, Pinned Interleaved A/B on Core 29)

Benchmark origin/main Mean Branch Mean Speedup / Delta Steady-State Heap Allocs
operation_slab/zero_copy 2.71 ns 2.15 ns 1.26x faster (-20.7%) 0 B / 0 allocs
operation_slab/single 1.84 ns 1.57 ns 1.17x faster (-14.3%) 0 B / 0 allocs
operation_slab/cancel 2.17 ns 2.01 ns 1.08x faster (-7.4%) 0 B / 0 allocs
operation_slab/multishot 2.15 ns 2.11 ns 1.02x faster (-1.9%) 0 B / 0 allocs
operation_id/payload_pack 605.77 ps 517.50 ps 1.17x faster (-14.6%) 0 B / 0 allocs
proactor/submit_dispatch_nop 165.36 ns 163.44 ns 1.01x faster (-1.2%) 0 B / 0 allocs
fixed_file/lease_release 260.05 ns 252.42 ns 1.03x faster (-2.9%) 0 B / 0 allocs
fixed_buffer/lease_release 19.86 ns 19.96 ns ~1.00x 0 B / 0 allocs

Verification Gates

  • cargo fmt --all -- --check — PASS
  • cargo clippy --workspace --all-targets -- -D warnings — PASS
  • cargo test --workspace — PASS (129 passed, 0 failed)
  • cargo bench --workspace --no-run — PASS
  • Max .rs file length across modified/added files: 786 lines (crates/liburing/src/operation_slab.rs, <= 800 limit).

Merge Danger

  • Door: Two-Way Door. Public OperationState, OperationSlab, CompletionSocketTable, FixedBufferRegistry, and FixedFileSet APIs preserve full backward compatibility; IdentityMap and OperationPhase remain private to the crate.
  • Blast Radius: crates/liburing/src/{fixed_buffers.rs, identity_map.rs, operation_slab.rs, socket_io.rs} and the new Criterion benchmark suite in crates/liburing/benches/uring_hotpath_bench.rs.

@trunkszi
trunkszi force-pushed the perf/criterion-hsm-hotpath branch from 4998125 to b3c0b08 Compare October 27, 2026 16:15
@trunkszi
trunkszi merged commit 157bbd8 into main Oct 27, 2026
1 check passed
@trunkszi
trunkszi deleted the perf/criterion-hsm-hotpath branch October 27, 2026 16:19
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