Tags: alii/al
Tags
value: hash enum cells lazily; +12% on the http hot path
Every enum construction eagerly hashed its payload — a full walk of every
field at every `Ok`/`Err`/`Header`/`Response`, per request, for a hash that
equality and maps almost never asked for. perf put `hash_value` at ~5% of a
keep-alive request's cycles; removing the walk bought +12% measured
(67.8k -> 77.3k req/s single-scheduler on an idle Ryzen 7800X3D, 100%
success), the extra over 5% being the payload cache lines the walk stopped
dragging through L1.
A cell now stores hash `0` ("not computed"); `EnumRef::hash` computes and
caches on first use. The in-place cache write is sound because a process
heap has exactly one owner thread (shared-nothing) — review verified the
write is strictly weaker than the existing `rc_increment`/`hollow_for_reuse`
in-place mutations, that no shared-read channel for a mortal cell exists,
and that the lazy inputs are byte-identical to the eager ones. Equality's
hash shortcut now fires only when BOTH sides are already computed; an
uncomputed side goes straight to the structural compare rather than paying
two payload walks to avoid one.
Frozen cells are the one place a lazy write can never happen (they are
shared across threads), so the publish path hashes the still-mortal SOURCE
cell before copying and freezing the image — review caught that published
toplevel globals would otherwise freeze with hash 0 and recompute on every
use forever. A true hash of 0 (one in 2^64) is recomputed per read rather
than cached.
The compile-time prehash constants still ride in the MakeEnumPayload
operand; nothing reads them at runtime now.
961 tests, clippy and fmt clean.
PreviousNext