Skip to content

tape: index the carry-forward search, so a quiet node stops costing the whole tape - #7

Merged
valeratrades merged 2 commits into
mainfrom
held-index
Aug 8, 2026
Merged

valeratrades merged 2 commits into
mainfrom
held-index

Conversation

@valeratrades

Copy link
Copy Markdown
Contributor

The bug

A frame carries every node's standing value, and Inner::held searched backwards from the cursor for the last fire of each node that was quiet. A node that fires twice a day — spl's market cap — or not at all that day — its classification — turned that into a walk over the entire retained tape, once per frame.

Measured on spl's 42-node graph at capacity 250 000, one day held whole:

action before after
␣ → /api/step 0.8 ms 0.9 ms
b → /api/step_until 80 ms 0.9 ms
chart click → /api/seek 93 ms 0.9 ms
n → /api/step_until_change 185 ms 1.0 ms

And it scaled with where the cursor sat — 0.8 ms at tick 100, 139 ms at tick 159 000. Now flat: 0.90 / 0.83 / 0.89 / 0.85 / 0.79 / 0.80 ms across the same six positions.

The fix

Inner::fired: per node, ascending, the ticks positions it fired on. held binary-searches it.

Positions and not abs ids because between thinning passes ticks only ever grows at the back, so a position already recorded cannot move — and thin, the one thing that does move them, rebuilds the index in the walk it was already making. Derived, so it stays out of TapeFile; load rebuilds it rather than trusting a file to agree with the ticks beside it, and TAPE_SCHEMA stays at 2.

What it cost

The point of the exercise was that this had to be strictly better — no cost pushed onto the record path.

before after
graph thread (Rec::on/drop, Recorder::at) — untouched
tape thread, viz_cost tape_s 1.087 / 1.118 / 1.107 s 1.109 / 1.108 / 1.174 s
RSS, spl at 250 000 391 MB 398 MB

tape_s medians are 1.107 vs 1.109 s across three runs each, inside the ±3% run-to-run spread — ~16 ns/tick, which is the ~7 Vec pushes per tick it adds. Memory is one usize per retained fire.

Why nobody saw it

The capacity sweep's synthetic mix had five nodes whose rarest fired hourly, so held always terminated quickly and the published latency was one nobody waits for. The mix gains a twice-a-day node, which is what makes this measurable at all — and the reactivity chart now shows the raw round trip instead of the round trip minus the loopback hop, which was flattering it for the same reason.

Re-swept block is in docs/.readme_assets/other.md: latency is now flat across the whole capacity range and is entirely the socket, so the prose says plainly that the price of capacity is memory and only memory.

Based on db45f52, so it sits on top of the Tape/Viz split.

🤖 Generated with Claude Code

valeratrades and others added 2 commits August 8, 2026 21:19
A frame carries every node's standing value, and `held` searched back from the
cursor for the last fire of each node that was quiet. A node that fires twice a
day — spl's market cap — or not at all that day — its classification — made that
a walk over the entire retained tape, once per frame. Measured on spl's 42-node
graph holding a day: 139ms to land a cursor at tick 159 000, 185ms for `n`, and
linear in wherever the cursor sat.

`fired` indexes it: per node, ascending, the positions it fired on. Positions
and not `abs` ids because between thinning passes `ticks` only grows at the
back, so a recorded position cannot move — and `thin`, the one thing that does
move them, rebuilds the index in the walk it was already making. Derived, so it
stays out of `TapeFile` and `load` rebuilds it.

Measured, same machine, same day, spl at capacity 250 000:

  seek/step_until/step_until_change   0.8-139ms  ->  flat 0.9ms
  tape thread (viz_cost tape_s)       1.107s     ->  1.109s, medians of 3
  RSS                                 391MB      ->  398MB
  graph thread                        untouched

The sweep's synthetic mix gains a twice-a-day node, without which none of this
was visible: its rarest node fired hourly, so the published latency was one
nobody waits for. The reactivity chart now shows the raw round trip rather than
the round trip minus the loopback hop, for the same reason.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
# Conflicts:
#	docs/.readme_assets/other.md
#	docs/capacity.txt
@valeratrades
valeratrades merged commit 2a6034a into main Aug 8, 2026
19 checks passed
@claude

claude Bot commented Aug 8, 2026

Copy link
Copy Markdown

Code review

Reviewed the core change in exec_viz/src/tape.rs: the new Inner::fired per-node fire-position index, held's binary search via partition_point, and how the index is kept consistent across absorb (tick-append), thin (retention/compaction), and load (deserialize). Also checked the capacity.rs benchmark harness changes (new twice-daily Cap node, reactivity metric change) and the regenerated docs/benchmark numbers.

What was checked:

  • Correctness of held's binary search against the old linear-scan semantics (confirmed it returns the same "newest fire at or before p" as the old reverse walk, including the ranks[i] > 0 <=> acts[i].vals.is_some() invariant it now relies on).
  • Index/bounds safety: whether self.fired[i] / self.ticks[*q] can ever go out of range, and whether fired can desync from ticks across absorb, thin, or load.
  • A specific concern raised during review -- that self.fired.resize(ranks.len(), ...) in absorb could truncate the index if ranks.len() ever shrank -- was traced through every mutation site of self.series (the source of ranks.len()) and confirmed impossible: self.series is push-only, so the length is monotonically non-decreasing and the resize can only grow.
  • Compile-level correctness (borrow/move ordering in load, type/iterator bounds on the new index() helper) and the example/doc changes for internal consistency.
  • No CLAUDE.md files exist in this repository, so no project-specific compliance rules applied.

Nothing rose to a high-confidence bug: the new index is built and consumed consistently everywhere it's touched, and the fix's own stated invariant (strictly better cursor latency, no added cost on the record path) holds up against the diff. One minor, low-severity observation (the pre-existing Viz::bytes() accounting doesn't include the new index's ~8 B/retained-fire) is out of scope for this diff since that function isn't touched by it.

@valeratrades
valeratrades deleted the held-index branch August 8, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant