[alloc+atomic] Optimize GhostTreeBStackAllocator - #39
Conversation
|
Perf data on my machine (mixed/uniform)
|
|
Per-op latency (ms), 10 samples/case, iters 9→90 on APFS SSD (my machine)
*4t deep-ratio is measured at iters=54 (criterion picked a different iter step, so the deepest common tree is shallower); its paired-median over common iters is 0.68, in line with the others. This shows average ~27.5% lower per-op latency, a great improvement. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the GhostTreeBstackAllocator (Rust + C) hot paths by avoiding per-operation heap allocations and reducing I/O during AVL updates via cached child heights, while also adding a C-only test/fuzz escape hatch to skip durable sync for faster fuzzing.
Changes:
- Add denormalized cached child-height fields to AVL nodes and thread known heights through insert/remove/rotations to avoid extra reads.
- Replace
Vec-allocated path buffers with fixed-size stack arrays on AVL operations (insert, remove-min, best-fit remove). - Add
BSTACK_TEST_NO_DURABLE_SYNCto makeplat_durable_synca no-op in C test/fuzz builds; remove the now-implemented optimization plan section fromPLANNED.md.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/alloc/ghost_tree.rs | Adds child-height caching + stack-based path tracking to reduce allocator critical-section work and I/O. |
| c/bstack_alloc.c | Mirrors the Rust AVL optimizations (cached heights, threaded rotations, stack paths) and bumps ALGT magic. |
| c/bstack.c | Adds compile-time test/fuzz option to skip durable sync for faster fuzzing. |
| PLANNED.md | Removes the planned item that is now implemented by this PR. |
Suppressed comments (1)
c/bstack_alloc.c:2376
nbfandnhare written byalgt_read_nodebut never read afterwards in this branch either, which can trigger-Wunused-but-set-variablewarnings. Consider explicitly marking them as used (or avoid reading them if not needed).
uint64_t size, left, right, right_sz, right_l, right_r;
int8_t nbf, right_bf; uint8_t nh, right_h;
if (algt_read_node(bs, node, &size, &nbf, &nh, &left, &right) != 0) return -1;
if (algt_read_node(bs, right, &right_sz, &right_bf, &right_h, &right_l, &right_r) != 0)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Description: Bring several optimization to
GhostTreeBStackAllocatorand its corresponding C implementation by child pointer and height caching, rotation threading, reducing dynamic heap allocation on hot path, and other techniques. In addition, allow C fuzzing to skip fsync, mirroring similar Rust optimization.Important Feature: No
Type: Allocator - Optimization
Magic Number: ALGT
Bulk: No
Tests: Included
Feature Flags: alloc + set
Breaking change: No
New Types: None
Rust Only: No
Fuzz: Yes
Safety Review: Needed: Crash Safety, Invariants, Thread Safety