Default ReleaseSafe inserts repeat object-cache absence probes

perfloop/tigerbeetle · INEFFICIENT ALGORITHM

https://perfloop.ai/t/oss/case_2c1db4y65h

Verdict

VERIFIED · settled 2026-09-04

What happened: The paired measurements met the required improvement.

Hypothesis

I ran a source trace from `execute_create` to `create_transfer`, `Groove.insert`, CacheMap, and SetAssociativeCache. The build configuration prefers ReleaseSafe. Each event that clears `create_transfer`'s early exits calls `transfers.insert` once; no insert happens for an event that returns an error, while linked scopes can later discard an otherwise inserted event.

`insert` first evaluates `assert(!objects_cache.has(primary_key))` and immediately calls `objects_cache.upsert(object)`. Transfers enable `objects_cache`; `has` delegates to `CacheMap.get`, and `upsert` delegates to `fetch_upsert`, whose cache path invokes `SetAssociativeCache.upsert` and its own `associate`/`search`. Therefore the default assertion-enabled path performs a separate same-key absence probe before the insertion probe. The removed delta is one cache/stash membership probe per such insert. I did not measure its CPU share, cache capacity, or whether ReleaseFast removes the assertion, so the performance benefit remains low-confidence.

Benchmark valid unique transfer batches at 1, 64, 1,024, and near the configured maximum in both ReleaseSafe and ReleaseFast. Record cache lookup/search counts, CPU samples attributable to CacheMap and SetAssociativeCache, and batch throughput and latency. The fused path must demonstrate one fewer probe in the applicable build and preserve outcomes for duplicate IDs, cache eviction into stash, linked-scope rollback, prefetch, and post-compaction lookup.

Change to test: Add a CacheMap insert-if-absent operation that validates absence and inserts from one cache/stash probe, then call it from `Groove.insert`. Preserve the pre-mutation duplicate-key failure, cache/stash eviction behavior, scope rollback, and lookup results.

Where it lives

perfloop/tigerbeetle

Evidence

ReleaseSafe execute_create to Groove.insert for one-transfer batches repeated 64 times with two valid accounts · 10 sample pairs

metric baseline candidate paired median change confidence range required result
ns/op 624.5 603.5 −3.4% (−21) −41 to −5 ≤ 0 PASSED

ReleaseSafe CacheMap inserts of 1,024 unique values per batch · 10 sample pairs

metric baseline candidate paired median change confidence range required result
ns/op 20 12 −37.5% (−7.5) −8 to −7 < −1 PASSED

Checks: 1 of 1 passed. Verification: no defect found.

Timeline