0063. Tagged map groups with a cache-resident fallback
- Status: Accepted; supersedes 0053 index probing only
- Date: 2026-10-31
- Plan: M8.6
- Review: Memory and representation
Context
ADR-0053 separates insertion-ordered entries from lookup. Large random-access maps pay for unrelated entry cache misses; small word-frequency maps instead need a very cheap hit path. M8.6 reserves this ADR number. Measurements and rejected candidates are in the results.
Decision
Keep the public runtime API, entry layout, hash function, load <=0.5 and u32 index sentinel. Add one tag byte per index slot: high seven hash bits for an occupied slot, 0x80 for empty; other high-bit controls are reserved. No removal API or tombstones. Keep seven cloned tail tags for wraparound group loads.
Above 16,384 entry capacity, scan eight-byte groups starting at the hash slot. Portable C11 uint64 SWAR produces exact match masks; arithmetic selects lanes, with no intrinsics or endian assumptions. Check full hashes/keys only after tag matches; a direct-hit fast path avoids group-mask work. Smaller maps retain scalar linear lookup. Both paths place entries at the first linear empty slot, so copies and growth can switch paths without changing order or reachability.
HRT_MAP_HUGEPAGE opts C builds into best-effort
madvise(MADV_HUGEPAGE) for allocations >=2 MiB,
before first touch. Guard platform support, advise only interior
OS pages, preserve errno, ignore failure. Follow hrt_mem.h's
caller- defined _DEFAULT_SOURCE /
_DARWIN_C_SOURCE convention. Default-on advice was
slower, so it is dropped from production defaults; no driver flag
changes.
Alternatives considered
- Always grouped, aligned buckets — the first trial nearly doubled word-frequency time; discard it. Hash-position groups alone still regressed that cache-resident workload; retain scalar lookup there.
- Default-on huge pages — final median 3683 vs 3048 ms without advice; discard the default, keep the portable opt-in mechanism for other hosts.
- SIMD intrinsics or lookup fusion — unnecessary platform/compiler scope; neither is part of this representation change.
Consequences
The retained large-table benchmark improves median 3521→3048 ms (13.4%) and best 3333→2953 ms (11.4%); RSS grows 788084→804552 KiB (2.1%). Word-frequency changes +2.1% median / +0.6% best, within noise. The capacity cutoff is a measured conservative policy, not a universal cache-size claim. Dense entries still own snapshots and iteration; hashing is not adversarially hardened. No dependencies, language semantics or diagnostics change.