grid: cache recent pens in front of the style dedup index #429
No reviewers
Labels
No labels
priority/P0
priority/P1
priority/P2
release/v0.1.0
status/blocked
status/planned
type/bug
type/design
type/test-gap
type/tracker
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set
Reference
natsukium/felis!429
Loading…
Reference in a new issue
No description provided.
Delete branch "grid/pen-intern-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Under DOOM-fire every SGR re-interns the pen, and the dedup lookup (hash, probe, enum-wise
Attributesequality) was ~24% of the parse thread's cycles on the floor bench.Change
StyleTable::internchecks a 1024-slot direct-mapped cache of recent(packed attributes, StyleId)pairs before the dedup map. DOOM sends38;5and48;5as separate SGRs, so the pen changes on 99.7% of SGRs, but it cycles among ~500 pens: the cache hits ~96% of interns (256 slots: 78%; 4096 buys 0.1% more).u64words (PenKey), so a probe compares two words instead of threeColorenums. That keeps the truecolor flood, which misses the cache on every cell, below its old instruction count.compactclears the cache, because compaction is the one place ids get renumbered.StyleTable'sPartialEqcomparesentriesonly, sincededupand the cache only index them.StyleTableperRowDeltamessage instead of one per row, so it does not zero the 24 KiB cache once per row.Rejected: skipping the intern when the SGR leaves the pen unchanged costs +2% instructions on doom, because the pen almost always changes. A single last-hit entry never hits. A lazily allocated cache cost +0.4–1.5% instructions across the floors for its per-intern bounds check. The decision is recorded in
docs/explanation/data-model/grid-and-cells.md"Style interning", and the figures are in the perf-trace cost map.Measurements
measure_parse_into_grid_floor, 35×106, interleaved A/B,instructions:u(deterministic):9fec9dbc)MiB/s, doom: 214 → 236 (load 11–24). Before the merge of main, at load 11–14: doom 203 → 219, csi 138 → 149, truecolor 287 → 285, ascii 509 → 513. Intern's share of doom parse cycles fell from ~24% to ~15%. What remains there is the slot load's latency and the three
Colorpacks, not the map.Tests
style_table::tests::the_recent_cache_returns_what_the_dedup_index_would: a proptest of the cachedinternagainst the uncached path, with colliding slots (2304 possible pens, 1024 slots) and interleaved compactions.table_gc::tests::sweeps_are_invisible_to_what_is_printed_afterwardsnow adds a small repeating palette (so a pen comes back after a compaction and hits the cache) and RIS, on top of the DECSC/DECRC and alt-screen steps it already had.compactclear is removed.json_v1::row::tests::rows_sharing_a_table_recode_as_rows_with_their_own.Closes #416