On this page

0317. All-size SWAR SwissTable probing, fast 64-bit mixing, and single-probe map.update

Context

ADR-0063 introduced 7-bit tag bytes and 8-way portable C11 SWAR group probing only above 16,384 entry capacity, retaining scalar linear probing for smaller maps such as word-freq (8,193 keys) and bench/maps (10,000 keys). Meanwhile, trt_map_hash used a multi-stage FNV/Murmur3 loop, and common map updates written as m = m.set(k, m.get_or(k, d) + 1) only fused into a single hmapslot probe for direct integer-arithmetic self-assignments — leaving record-field updates (s = s with { counts: s.counts.update(k, 0) { n -> n + 1 } }) and general value updates (vec, str, records, conditional logic) paying two full hashes and two probes.

Decision

  1. All-size SWAR SwissTable (>= 16 index slots). Every allocated map has at least 8 entry capacity (16 index slots plus 7 cloned tail tags). Remove the cap <= 16384 scalar fallback in trt_map_probe so all non-trivial maps use portable 64-bit SWAR 8-way tag-group probing with a single 64-bit group load per iteration, preceded by direct-hit and direct-empty home-slot fast paths and skipping tombstone mask extraction when m->tombstones == 0.
  2. Fast 64-bit wyhash/rapidhash-class mixer. Replace the FNV/Murmur3 body of trt_map_hash with a wymix (128-bit multiply-xor-fold via unsigned __int128 when __SIZEOF_INT128__ is available and not __TINYC__, with a portable C11 32-bit-split uint64_t fallback). All unaligned loads use memcpy (strict C11, no UB), TRT_MAP_SEED continues to seed the mixer, and the uint32_t hash output and dense insertion-ordered entry layout remain unchanged.
  3. Single-probe m.update(key, default_val) { v -> new_v } on map<K, V>. Reuse the existing trailing-block method-call grammar (zero parser or compact codec changes). Evaluation order is strictly left-to-right: m, key, default_val, then the block { v -> new_v } receiving the existing value (if present) or default_val (if absent). Lowering emits ordinary Core IR (MapFind + If(MapValueAt / default) + block + MapSet), so ADR-0278 ownership analysis automatically rewrites unique self-updates and record-field takes (s = s with { counts: s.counts.update(...) }) to MapSetUnique, regions/place handles arena promotion, --report=copies reports remaining copy sites, and tenon interp has exact parity without new IR opcodes. cgen/map.rs generalizes upsert to fuse MapFind + MapValueAt/default
    • pure/non-aliasing update body + MapSet[Unique] into a single hmapslot hash and probe for any value type and destination local (including record-field takes), falling back cleanly to 2-probe IR when the body references m or may observe an aliased map.

Alternatives considered

Consequences