diff --git a/README.md b/README.md index 2c1443e..906892d 100644 --- a/README.md +++ b/README.md @@ -88,15 +88,14 @@ An op can name a tick that has not been recorded yet. The server says so (`pendi ### Picking a `capacity` -`capacity` is the only number `Viz::new` asks for that has no right answer — it is RAM traded -against reactivity, and the exchange rate is your graph's, not this crate's. What it constrains: +`capacity` is the only number `Tape::new` asks for that has no right answer — it buys scrollback with +RAM, and the exchange rate is your graph's, not this crate's. What it constrains: | | | |---|---| | `capacity / 2` | the newest ticks kept **whole** — the stretch that stays tick-exact | | `capacity / 4` | the ceiling on the thinned *backbone*, and so how deep the squeeze goes | | `capacity / 2` | the recycle channel's depth: one pass frees between a quarter and a half of the buffer, and the recorder takes all of it back rather than allocating | -| `capacity` | the bound on the carry-forward scan a frame does for every quiet node, which is what landing a cursor costs | Thinning is **per node, not per tick**: a pass raises the exponent of whichever node is claiming most of the backbone until the backbone fits, so a node firing 288 times a day keeps all 288 while the @@ -108,40 +107,60 @@ that each want ~3 000 land on ~1 790 apiece, and everything rarer than that keep had. Read the other way: a 5-minute bar over three days is 864 fires and is safe from about 8 000; over a month it is 8 640 and wants ~65 000. -Bigger is not free, and the price is not where it looks. Recording cost does not move with -`capacity` at all — the graph thread's leg of a fire is the same two renderings either way. What -moves is the cost of *landing* a cursor, because a frame carries every node's standing value and a -node quiet for a while is found by scanning back for it. +Three prices, and they are not the same shape: -The block below is one synthetic graph on one machine. `Viz::bytes` is exported so the same reading -can be taken against yours. +- **Memory is linear**, and it is the one you actually pay. Roughly 550 B per retained tick for the + mix below; a 42-node graph runs nearer 2.4 KB. +- **Cursor latency is flat.** Every replay op is a binary search, so a keypress costs the same + against 260 000 retained ticks as against 2 000 — the whole latency column below is the loopback + socket, and the tape's own share does not clear the noise. +- **Absorption grows**, about 2× from 2 048 to 262 144. Not the graph thread — its leg of a fire is + the same two renderings either way — but the tape thread's, which allocates fresh columns where a + smaller buffer would have been handing recycled ones back. Under `Block` that is replay + throughput; under `Drop` it is not latency either, it is `dropped`. + +The flat middle line was not always true. A frame carries every node's standing value, and a node +that has been quiet is found by searching back for its last fire — which used to be a linear scan. On +a 42-node graph holding a day, one node that fires twice a day was enough to put a scrub at 139ms, +growing with wherever the cursor sat. `Inner::fired` indexes it, and the mix below now carries a +twice-a-day node so that number cannot quietly go back to being one nobody waits for. + +The block is one synthetic graph on one machine. `Viz::bytes` is exported so the same reading can be +taken against yours. ``` -318420 ticks (2 days at spl's 159210/day), 5 nodes, 107 B/tick of card faces -fires over the run: Book=318420 Screen=3185 Bar:1m=2895 Bar:5m=579 Bar:1h=49 +318420 ticks (2 days at spl's 159210/day), 6 nodes, 107 B/tick of card faces +fires over the run: Book=318420 Screen=3185 Bar:1m=2895 Bar:5m=579 Bar:1h=49 Cap=4 footprint — Viz::bytes over the retained ticks - 2048 │▬ 3.0 MB (1477 B/tick) - 8192 │▬▬ 5.4 MB (818 B/tick) - 20000 │▬▬▬▬ 11.3 MB (665 B/tick) - 65536 │▬▬▬▬▬▬▬▬▬▬▬ 33.8 MB (554 B/tick) - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 132.6 MB (524 B/tick) - -reactivity — /api/seek mid-tape *above* a bare 53µs loopback hop, median of 64 - 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 13µs - 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 13µs - 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 13µs - 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 14µs - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 34µs + 2048 │▬ 1.2 MB (701 B/tick) + 8192 │▬ 4.0 MB (637 B/tick) + 20000 │▬▬▬▬ 9.8 MB (594 B/tick) + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬ 34.1 MB (558 B/tick) + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 121.0 MB (548 B/tick) + +reactivity — one /api/seek mid-tape, median of 64; the bare loopback hop under it is 53µs + 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 68µs + 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 66µs + 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 83µs + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 66µs + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 68µs + +absorption — the whole recording's wall clock per tick, tape-thread bound under `Block` + 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 761ns + 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 795ns + 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 957ns + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1258ns + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1443ns addressability — fires still reachable by `step_until`, against the run's own - capacity retained Book Screen Bar:1m Bar:5m Bar:1h - 2048 2007 2007/318420 251/3185 231/2895 147/579 49/49 - 8192 6557 6557/318420 691/3185 899/2895 579/579 49/49 - 20000 16951 16951/318420 1796/3185 1784/2895 579/579 49/49 - 65536 61047 61047/318420 3185/3185 2895/2895 579/579 49/49 - 262144 252884 252884/318420 3185/3185 2895/2895 579/579 49/49 + capacity retained Book Screen Bar:1m Bar:5m Bar:1h Cap + 2048 1767 1767/318420 248/3185 229/2895 147/579 49/49 4/4 + 8192 6316 6316/318420 689/3185 897/2895 579/579 49/49 4/4 + 20000 16395 16395/318420 1793/3185 1781/2895 579/579 49/49 4/4 + 65536 61059 61059/318420 3185/3185 2895/2895 579/579 49/49 4/4 + 262144 220713 220713/318420 3185/3185 2895/2895 579/579 49/49 4/4 ``` diff --git a/docs/.readme_assets/other.md b/docs/.readme_assets/other.md index 336a672..058d249 100644 --- a/docs/.readme_assets/other.md +++ b/docs/.readme_assets/other.md @@ -1,14 +1,13 @@ ### Picking a `capacity` -`capacity` is the only number `Viz::new` asks for that has no right answer — it is RAM traded -against reactivity, and the exchange rate is your graph's, not this crate's. What it constrains: +`capacity` is the only number `Tape::new` asks for that has no right answer — it buys scrollback with +RAM, and the exchange rate is your graph's, not this crate's. What it constrains: | | | |---|---| | `capacity / 2` | the newest ticks kept **whole** — the stretch that stays tick-exact | | `capacity / 4` | the ceiling on the thinned *backbone*, and so how deep the squeeze goes | | `capacity / 2` | the recycle channel's depth: one pass frees between a quarter and a half of the buffer, and the recorder takes all of it back rather than allocating | -| `capacity` | the bound on the carry-forward scan a frame does for every quiet node, which is what landing a cursor costs | Thinning is **per node, not per tick**: a pass raises the exponent of whichever node is claiming most of the backbone until the backbone fits, so a node firing 288 times a day keeps all 288 while the @@ -20,47 +19,60 @@ that each want ~3 000 land on ~1 790 apiece, and everything rarer than that keep had. Read the other way: a 5-minute bar over three days is 864 fires and is safe from about 8 000; over a month it is 8 640 and wants ~65 000. -Bigger is not free, and the price is not where it looks. Recording cost does not move with -`capacity` at all — the graph thread's leg of a fire is the same two renderings either way. What -moves is the cost of *landing* a cursor, because a frame carries every node's standing value and a -node quiet for a while is found by scanning back for it. +Three prices, and they are not the same shape: -The block below is one synthetic graph on one machine. `Viz::bytes` is exported so the same reading -can be taken against yours. +- **Memory is linear**, and it is the one you actually pay. Roughly 550 B per retained tick for the + mix below; a 42-node graph runs nearer 2.4 KB. +- **Cursor latency is flat.** Every replay op is a binary search, so a keypress costs the same + against 260 000 retained ticks as against 2 000 — the whole latency column below is the loopback + socket, and the tape's own share does not clear the noise. +- **Absorption grows**, about 2× from 2 048 to 262 144. Not the graph thread — its leg of a fire is + the same two renderings either way — but the tape thread's, which allocates fresh columns where a + smaller buffer would have been handing recycled ones back. Under `Block` that is replay + throughput; under `Drop` it is not latency either, it is `dropped`. + +The flat middle line was not always true. A frame carries every node's standing value, and a node +that has been quiet is found by searching back for its last fire — which used to be a linear scan. On +a 42-node graph holding a day, one node that fires twice a day was enough to put a scrub at 139ms, +growing with wherever the cursor sat. `Inner::fired` indexes it, and the mix below now carries a +twice-a-day node so that number cannot quietly go back to being one nobody waits for. + +The block is one synthetic graph on one machine. `Viz::bytes` is exported so the same reading can be +taken against yours. ``` -318420 ticks (2 days at spl's 159210/day), 5 nodes, 107 B/tick of card faces -fires over the run: Book=318420 Screen=3185 Bar:1m=2895 Bar:5m=579 Bar:1h=49 +318420 ticks (2 days at spl's 159210/day), 6 nodes, 107 B/tick of card faces +fires over the run: Book=318420 Screen=3185 Bar:1m=2895 Bar:5m=579 Bar:1h=49 Cap=4 footprint — Viz::bytes over the retained ticks - 2048 │▬ 1.4 MB (679 B/tick) - 8192 │▬ 4.2 MB (639 B/tick) - 20000 │▬▬▬ 10.0 MB (592 B/tick) - 65536 │▬▬▬▬▬▬▬▬▬▬▬ 34.0 MB (557 B/tick) - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 138.2 MB (546 B/tick) + 2048 │▬ 1.2 MB (701 B/tick) + 8192 │▬ 4.0 MB (637 B/tick) + 20000 │▬▬▬▬ 9.8 MB (594 B/tick) + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬ 34.1 MB (558 B/tick) + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 121.0 MB (548 B/tick) -reactivity — /api/seek mid-tape *above* a bare 55µs loopback hop, median of 64 - 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 11µs - 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 12µs - 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 13µs - 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 13µs - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 31µs +reactivity — one /api/seek mid-tape, median of 64; the bare loopback hop under it is 53µs + 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 68µs + 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 66µs + 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 83µs + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 66µs + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 68µs absorption — the whole recording's wall clock per tick, tape-thread bound under `Block` - 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 567ns - 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 706ns - 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 956ns - 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1085ns - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1334ns + 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 761ns + 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 795ns + 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 957ns + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1258ns + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1443ns addressability — fires still reachable by `step_until`, against the run's own - capacity retained Book Screen Bar:1m Bar:5m Bar:1h - 2048 2007 2007/318420 251/3185 231/2895 147/579 49/49 - 8192 6557 6557/318420 691/3185 899/2895 579/579 49/49 - 20000 16951 16951/318420 1796/3185 1784/2895 579/579 49/49 - 65536 61047 61047/318420 3185/3185 2895/2895 579/579 49/49 - 262144 252884 252884/318420 3185/3185 2895/2895 579/579 49/49 + capacity retained Book Screen Bar:1m Bar:5m Bar:1h Cap + 2048 1767 1767/318420 248/3185 229/2895 147/579 49/49 4/4 + 8192 6316 6316/318420 689/3185 897/2895 579/579 49/49 4/4 + 20000 16395 16395/318420 1793/3185 1781/2895 579/579 49/49 4/4 + 65536 61059 61059/318420 3185/3185 2895/2895 579/579 49/49 4/4 + 262144 220713 220713/318420 3185/3185 2895/2895 579/579 49/49 4/4 ``` diff --git a/docs/capacity.txt b/docs/capacity.txt index d5012c8..a470754 100644 --- a/docs/capacity.txt +++ b/docs/capacity.txt @@ -1,31 +1,31 @@ -318420 ticks (2 days at spl's 159210/day), 5 nodes, 107 B/tick of card faces -fires over the run: Book=318420 Screen=3185 Bar:1m=2895 Bar:5m=579 Bar:1h=49 +318420 ticks (2 days at spl's 159210/day), 6 nodes, 107 B/tick of card faces +fires over the run: Book=318420 Screen=3185 Bar:1m=2895 Bar:5m=579 Bar:1h=49 Cap=4 footprint — Viz::bytes over the retained ticks - 2048 │▬ 1.4 MB (679 B/tick) - 8192 │▬ 4.2 MB (639 B/tick) - 20000 │▬▬▬ 10.0 MB (592 B/tick) - 65536 │▬▬▬▬▬▬▬▬▬▬▬ 34.0 MB (557 B/tick) - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 138.2 MB (546 B/tick) + 2048 │▬ 1.2 MB (701 B/tick) + 8192 │▬ 4.0 MB (637 B/tick) + 20000 │▬▬▬▬ 9.8 MB (594 B/tick) + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬ 34.1 MB (558 B/tick) + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 121.0 MB (548 B/tick) -reactivity — /api/seek mid-tape *above* a bare 55µs loopback hop, median of 64 - 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 11µs - 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 12µs - 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 13µs - 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 13µs - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 31µs +reactivity — one /api/seek mid-tape, median of 64; the bare loopback hop under it is 53µs + 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 68µs + 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 66µs + 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 83µs + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 66µs + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 68µs absorption — the whole recording's wall clock per tick, tape-thread bound under `Block` - 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 567ns - 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 706ns - 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 956ns - 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1085ns - 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1334ns + 2048 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 761ns + 8192 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 795ns + 20000 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 957ns + 65536 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1258ns + 262144 │▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1443ns addressability — fires still reachable by `step_until`, against the run's own - capacity retained Book Screen Bar:1m Bar:5m Bar:1h - 2048 2007 2007/318420 251/3185 231/2895 147/579 49/49 - 8192 6557 6557/318420 691/3185 899/2895 579/579 49/49 - 20000 16951 16951/318420 1796/3185 1784/2895 579/579 49/49 - 65536 61047 61047/318420 3185/3185 2895/2895 579/579 49/49 - 262144 252884 252884/318420 3185/3185 2895/2895 579/579 49/49 + capacity retained Book Screen Bar:1m Bar:5m Bar:1h Cap + 2048 1767 1767/318420 248/3185 229/2895 147/579 49/49 4/4 + 8192 6316 6316/318420 689/3185 897/2895 579/579 49/49 4/4 + 20000 16395 16395/318420 1793/3185 1781/2895 579/579 49/49 4/4 + 65536 61059 61059/318420 3185/3185 2895/2895 579/579 49/49 4/4 + 262144 220713 220713/318420 3185/3185 2895/2895 579/579 49/49 4/4 diff --git a/exec_viz/examples/capacity.rs b/exec_viz/examples/capacity.rs index 0ff1fc0..698795a 100644 --- a/exec_viz/examples/capacity.rs +++ b/exec_viz/examples/capacity.rs @@ -36,7 +36,13 @@ const BAR: usize = 44; const MIN: usize = TICKS_PER_DAY / 1440; /// The book node carries the whole per-tick face budget on its own: spl spreads it over four that /// all fire on nearly every tick, and what the tape holds is the sum either way. -const NODES: [Node; 5] = [ +/// +/// `Cap` is here because a mix without it measures the wrong thing. A frame carries every node's +/// standing value, and a node that has been quiet is found by searching back for its last fire — so +/// the cost of landing a cursor is set by the *rarest* node, not the busiest. spl's market cap fires +/// twice a day and its classification can go a whole one without firing; a mix whose rarest node +/// still fires hourly reports a latency nobody has. +const NODES: [Node; 6] = [ Node { name: "Book", period: 1, @@ -67,6 +73,12 @@ const NODES: [Node; 5] = [ face: 24, dims: &[5], }, + Node { + name: "Cap", + period: TICKS_PER_DAY / 2, + face: 24, + dims: &[1], + }, ]; const CARD: &str = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; const BEGIN: &str = ""; @@ -284,11 +296,11 @@ fn render(rows: &[Row], fires: &[usize], ticks: usize, hop_us: f64) -> String { chart(format_args!("footprint — Viz::bytes over the retained ticks\n"), &|r| r.bytes as f64 / 1e6, &|r, v| { format!("{v:.1} MB ({} B/tick)", r.bytes / r.retained) }); - // Above the hop, not including it: a loopback round trip is the larger half of every reading here - // and none of it is the tape's, so charting the raw number draws five bars of the same length. + // What one keypress costs, socket included. An earlier version charted this minus the loopback hop, + // which drew a prettier curve and told the reader a number they never wait for. chart( - format_args!("reactivity — /api/seek mid-tape *above* a bare {hop_us:.0}µs loopback hop, median of {SAMPLES}\n"), - &|r| (r.seek_us - hop_us).max(0.0), + format_args!("reactivity — one /api/seek mid-tape, median of {SAMPLES}; the bare loopback hop under it is {hop_us:.0}µs\n"), + &|r| r.seek_us, &|_, v| format!("{v:.0}µs"), ); diff --git a/exec_viz/src/tape.rs b/exec_viz/src/tape.rs index abd6672..6f3d374 100644 --- a/exec_viz/src/tape.rs +++ b/exec_viz/src/tape.rs @@ -99,6 +99,7 @@ impl Tape { opened: 0, fires: Vec::new(), keep: Vec::new(), + fired: Vec::new(), sealed: false, dropped: dropped.clone(), series: Vec::new(), @@ -246,6 +247,7 @@ impl Viz { )); } let file: TapeFile = rmp_serde::decode::from_read(&mut r).map_err(std::io::Error::other)?; + let ticks: VecDeque = file.ticks.into(); Ok(Self { inner: Arc::new(Mutex::new(Inner { @@ -254,10 +256,11 @@ impl Viz { bucket_ms: file.bucket_ms, topology: file.topology, cost: file.cost, - ticks: file.ticks.into(), opened: file.opened, fires: file.fires, keep: file.keep, + fired: index(&ticks), + ticks, sealed: true, dropped: Arc::new(AtomicUsize::new(file.dropped)), series: file.series, @@ -597,6 +600,14 @@ pub(crate) struct Inner { /// Per-node "keep one fire in `2^keep[i]`", positional with `topology` and only ever raised — /// see [`Inner::thin`]. keep: Vec, + /// Per node, ascending, the `ticks` *positions* it fired on — what [`Inner::held`] binary-searches + /// instead of scanning. Positions and not `abs` ids because between thinning passes `ticks` only + /// grows at the back, so a position already recorded cannot move; [`Inner::thin`], which is the + /// one thing that does move them, rebuilds this in the walk it was already making. + /// + /// Derived, so it is not in [`TapeFile`] — [`Viz::load`] rebuilds it rather than trusting a file + /// to agree with the ticks beside it. + fired: Vec>, /// The recording is over — see [`Inner::head`]. sealed: bool, /// The recorder's drop tally, shared — see [`Recorder::dropped`]. @@ -672,6 +683,15 @@ impl Inner { debug_assert!(self.ticks.len() < self.capacity); let abs = self.opened; self.opened += 1; + let p = self.ticks.len(); + // After the push, so `p` is the position the tick lands on. Appending only ever extends each + // node's list at the back, which is what keeps them ascending without a sort. + self.fired.resize(ranks.len(), Vec::new()); + for (i, r) in ranks.iter().enumerate() { + if *r > 0 { + self.fired[i].push(p); + } + } self.ticks.push_back(Tick { abs, ts_ns, acts, ranks }); freed } @@ -728,6 +748,7 @@ impl Inner { false => freed.push(t.acts), } } + self.fired = index(kept.iter()); self.ticks = kept; freed } @@ -835,10 +856,15 @@ impl Inner { /// Node `i`'s newest act at or before position `p` that fired; `None` if it never has. Searched /// rather than stamped, so what a scrubbed frame carries forward is a value the tape can still /// show — a remembered tick number would outlive the tick a thinning pass dropped. - /// ponytail: linear scan, bounded by `capacity`; index the fires per node if a frame ever costs - /// enough to feel. + /// + /// Searched over [`Inner::fired`] rather than back over the ticks: a frame calls this once per + /// quiet node, and a node that has not fired for a long stretch — a twice-a-day market cap, a + /// classification that never triggers — walked the whole retained tape for it. That put a scrub + /// at 139ms on a 42-node graph holding a day, growing linearly with where the cursor sat. fn held(&self, i: usize, p: usize) -> Option> { - self.ticks.iter().take(p + 1).rev().find_map(|t| t.acts.get(i).filter(|a| a.vals.is_some())) + let fired = self.fired.get(i)?; + let q = fired[..fired.partition_point(|&q| q <= p)].last()?; + self.ticks[*q].acts.get(i).filter(|a| a.vals.is_some()) } /// `n` retained ticks on, not `n` absolute ones: in a thinned stretch the ticks between two @@ -955,6 +981,21 @@ impl From<&Plot> for PlotOut { } } +/// Per node, the positions in `ticks` it fired on — [`Inner::fired`] built from scratch, which is +/// what both the thinning pass and a tape read back off disk need. Ascending because the ticks are. +fn index<'a>(ticks: impl IntoIterator) -> Vec> { + let mut fired: Vec> = Vec::new(); + for (p, t) in ticks.into_iter().enumerate() { + fired.resize(fired.len().max(t.ranks.len()), Vec::new()); + for (i, r) in t.ranks.iter().enumerate() { + if *r > 0 { + fired[i].push(p); + } + } + } + fired +} + /// Drops module paths at every depth, so a card reads as the types it names: /// `Buffer` /// → `Buffer`. A segment is a module iff it starts