Give hot dumped types one-letter serde names
Should also be improved by https://github.com/twittner/minicbor/pull/73
Session dumps are CBOR maps keyed by field and variant name, so key strings are most of a dump.
Measured on two sessions, key strings were 76% of a 500-snippet, 250-function REPL session and 69% of a session holding 2,000 small dicts.
The worst offenders are types written once per value, heap entry or location: every Value wrote its variant name (InternString is 13 bytes around a 1–3 byte id), every heap entry refcount/color/data, every dict item key/value/hash.
This renames every field and variant of those types to one upper-case letter (first letter of the name, else the next unused letter in it, else the first unused letter of the alphabet):
Value, HeapEntry, CcColor, List, Tuple, Dict (its hand-written impl), DictEntry, SetEntry, CodeRange, LocationEntry and CodeLoc.
Everything else keeps readable names; per-function and one-off types are a small share of a dump.
Notes for review:
HeapEntryandCcColorare inheap/mod.rs; the change there is serde attributes only.CodeLocis public inmonty-types, so its serde shape for hosts becomes{"L": …, "C": …}.HeapDatavariants are not renamed:heap_payloads!forwards variant attributes toHeapReadOutput, which has no serde derive.- Dumps are unpublished in this format, so there are no aliases;
dump_v13.binis regenerated (18.7 KB → 12.3 KB). CLAUDE.mdrecords the convention: a new field or variant on these types takes an unused letter.- #909 adds
SuspendPositiontocode.rs; it should get the same treatment once both land.
Measured with these renames applied on top of #909:
| before | after | |
|---|---|---|
| 2,000-dict session dump | 817 KB | 407 KB |
| 500-snippet session dump | 322 KB | 211 KB |
session_load (local criterion) | 588 µs | 541 µs (−8.6%) |
session_dump (local criterion) | 145.6 µs | 149.0 µs (noise) |
On CodSpeed most of session_dump's cost was glibc realloc copying the growing buffer, which the local macOS run does not show, so CodSpeed is the better measure of dump time.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DFJ9rUjXVHCtQpxhZvoiGb
Summary by cubic
Shrinks session dumps by renaming serde fields and variants on frequently written types to single upper-case letters. Key strings were ~70% of dump size; this halves it (817 KB → 407 KB for a 2,000-dict session, 322 KB → 211 KB for a 500-snippet session) while load time drops roughly 8% and dump time is unchanged.
Notes
- Renames fields on per-value, per-heap-entry, per-function, and per-frame types:
Value,HeapEntry,CcColor,List,Tuple,Dict,DictEntry,SetEntry,CodeRange,LocationEntry,CodeLoc,Function,Signature,Identifier,NameScope,Code,ExceptionEntry,SerializedFrame,Instance,Closure,FunctionDefaults, and the hotHeapDatavariants; all other types keep readable names. CodeLocis public inmonty-types, so its host-facing serde shape becomes{"L": …, "C": …}.- Dumps are unpublished in this format, so no aliases are needed;
dump_v13.binis regenerated. HeapReadOutputno longer repeats the registry's serde attributes, since they cannot apply to it; the registry's "append-only" notes are dropped since CBOR tags variants by name, not position.dump_rejects_transient_gc_colorswas updated to forge the now one-letterC/Bkeys instead of the old text keys.- The datatest harness now round-trips every non-suspending case's idle heap through the dump codec and re-dumps the result, which must match byte for byte, except
xfailcases whose expected failure must come from the run itself; mount-fs suspensions also round-trip so open files pass through the dump format. - The dump fixture was expanded to cover previously undumped heap types (iterators, dict views, dates, bytes, ranges, slices, bound methods,
random.Random) and now suspends inside anexec()frame with a globals dict,finally,except, and__init__; regenerating it asserts the suspension landed onhost_call.slice.indices()is documented as unimplemented. CLAUDE.mddocuments the convention: new fields or variants on these types take an unused letter.