Perf harness: large-Home fixtures, edit storms, perf-VM gate #44

Closed
opened 2026-10-13 18:29:47 +00:00 by kayg · 12 comments
Owner

kayg: "always benchmark/check for performance with a lot of edits/lots of notes". Build the harness every feature is measured with.

  • Fixture generator: realistic Homes of 1k / 10k / 100k notes (daily notes with logs, links, tags, long notes up to 50k words, attachments refs), deterministic by seed.
  • Edit storms: 10k+ edits in one note, many collaborators, outside edits.
  • Metrics: server startup to /healthz, open note, list/tag query, journal catch-up, typing keystroke→paint (browser), sync round trip, save ack, memory, disk writes.
  • Runs on the perf VM (no host cache, quiet), median of N, noise bands; results posted per PR; budgets in docs, regressions block merge (ADR 0005).
kayg: "always benchmark/check for performance with a lot of edits/lots of notes". Build the harness every feature is measured with. - Fixture generator: realistic Homes of 1k / 10k / 100k notes (daily notes with logs, links, tags, long notes up to 50k words, attachments refs), deterministic by seed. - Edit storms: 10k+ edits in one note, many collaborators, outside edits. - Metrics: server startup to /healthz, open note, list/tag query, journal catch-up, typing keystroke→paint (browser), sync round trip, save ack, memory, disk writes. - Runs on the perf VM (no host cache, quiet), median of N, noise bands; results posted per PR; budgets in docs, regressions block merge (ADR 0005).
Author
Owner

First perf baseline (PR #49)

Perf VM 10.69.69.63: Linux 6.12, 4 vCPUs, 7.7 GB, ext4 on a non-rotational disk with no host cache; page cache dropped before every server start. dev at 5e727fd + the harness (release build). Fixtures seed 1. Warm metrics: 5 runs per size, each a fresh server; p50/p95 = median over runs of each run's p50/p95; noise = spread of the run p50s over their median. Cold (never-indexed Home): 5 runs at 1k and 10k, 1 at 100k (18 min). Ran after the #14 benchmark finished, nothing else running.

metric unit 1k p50 / p95 10k p50 / p95 100k p50 / p95 worst noise
startup.healthz ms 36.7 / 57.5 40.2 / 61.9 57.3 / 154 224%
cold.startup ms 128 / 351 91.1 / 147 100 / 100 189%
cold.first_list ms 134 / 681 187 / 221 805 / 805 452%
cold.index s 13.8 / 15.2 129 / 141 1098 / 1098 47%
cold.notes_per_s notes/s 72.5 / 106 77.6 / 125 91.1 / 91.1 70%
cold.disk_written MB 13.0 / 13.0 128 / 128 1278 / 1278 0%
cold.mem_peak MB 14.5 / 14.5 33.1 / 33.4 203 / 203 3%
home.first_list ms 34.0 / 37.8 202 / 230 2465 / 3200 68%
home.list ms 5.50 / 8.30 54.8 / 65.5 571 / 705 66%
journal.catch_up ms 29.1 / 54.0 313 / 449 4162 / 5329 112%
journal.entries count 3283 / 5391 30655 / 51532 307656 / 467343 133%
open.note ms 43.7 / 51.7 41.8 / 47.7 26.6 / 46.2 113%
open.api_get ms 19.9 / 46.6 19.6 / 27.5 14.4 / 33.7 170%
open.long_note ms 18.3 / 307 250 / 276 30.8 / 499 1614%
sync.round_trip ms 10.4 / 18.4 9.22 / 26.9 11.8 / 53.7 77%
sync.save_ack ms 10.3 / 18.5 23.9 / 44.5 33.9 / 60.5 113%
storm.save_ack ms 335 / 601 312 / 610 377 / 803 32%
storm.edits_per_s edits/s 79.6 / 88.1 87.1 / 105 74.0 / 90.3 47%
storm.typing s 126 / 131 115 / 135 135 / 179 51%
storm.converge ms 187 / 194 179 / 201 482 / 688 104%
storm.disk_written MB 203 / 210 202 / 219 819 / 862 21%
storm.outside_edits count 250 / 261 229 / 269 269 / 356 50%
storm.dropped_clients count 0.00 / 0.00 0.00 / 0.00 0.00 / 0.00 0%
mem.idle MB 10.3 / 10.4 10.3 / 10.4 10.3 / 10.5 2%
mem.after_list MB 13.1 / 13.8 20.2 / 20.3 169 / 169 64%
mem.after_opens MB 20.9 / 21.4 41.3 / 45.6 513 / 576 37%
mem.peak MB 24.7 / 27.8 45.0 / 50.3 589 / 602 22%
shutdown ms 26.7 / 48.8 24.1 / 45.0 66.3 / 87.6 100%

Noise is high on single-sample metrics (startup, long note: one sample per run) because every fsync and cold read on this disk is slow and jumpy; the latency distributions (200 to 10,000 samples per run) are steadier (round trip 27-77%, storm ack 19-32%).

What looks like a real problem

  1. Every start journals a fake notes.changed (by: outside) for every note never opened. watch::changed_on_disk compares the file hash with history's base_hash, which unopened notes don't have. Confirmed in the 10k journal: 50,164 notes.changed after 6 starts vs 10,000 notes.created. At 100k: 100k file reads + 100k journal rows per restart (470k entries after 6 starts, catch-up 4-5 s), and it probably drives the 600 MB peak and the worse typing latency at 100k.
  2. First-start indexing: ~80-125 notes/s. 100k notes = 18 min and 1.3 GB written (13 KB/note): one ids.jsonl fsync + one journal write per note.
  3. ~80-100 keystrokes/s per note, ~20 KB written per keystroke, save ack 300-800 ms under the storm. Each change is its own synchronous = FULL history transaction and the room awaits it before the next message, so nothing is grouped. (#32)
  4. Sync round trip = fsync time (~10 ms p50, up to 54 ms p95 at 100k): fan-out waits for durable history. (#32)
  5. 100k Home: first notes.list 2.5 s, later ones 0.6 s (7 MB answer), 170 MB RSS after listing. Needs paging / background index load.
  6. First open of a 50k-word note: 250-500 ms (seed + history write); reopen from history ~20-30 ms.

Correctness: the storm (4 clients x 2,500 keystrokes with save checks, outside app rewriting the file every 500 ms, ~250 rewrites per run) never lost or doubled text in 15 runs, all copies converged in ~0.2 s (0.5 s at 100k), file == note after save, no client dropped.

Budgets proposed in docs/perf/budgets.md / perf/budgets.json: gated limits just above today's numbers, targets (not gated yet) for the items above. The browser keystroke-to-paint number is still the existing @perf Playwright test (perf/browser.sh); running it on a big fixture Home is the next step.

## First perf baseline (PR #49) Perf VM 10.69.69.63: Linux 6.12, 4 vCPUs, 7.7 GB, ext4 on a non-rotational disk with no host cache; page cache dropped before every server start. `dev` at 5e727fd + the harness (release build). Fixtures seed 1. Warm metrics: 5 runs per size, each a fresh server; p50/p95 = median over runs of each run's p50/p95; noise = spread of the run p50s over their median. Cold (never-indexed Home): 5 runs at 1k and 10k, 1 at 100k (18 min). Ran after the #14 benchmark finished, nothing else running. | metric | unit | 1k p50 / p95 | 10k p50 / p95 | 100k p50 / p95 | worst noise | |---|---|---:|---:|---:|---:| | `startup.healthz` | ms | 36.7 / 57.5 | 40.2 / 61.9 | 57.3 / 154 | 224% | | `cold.startup` | ms | 128 / 351 | 91.1 / 147 | 100 / 100 | 189% | | `cold.first_list` | ms | 134 / 681 | 187 / 221 | 805 / 805 | 452% | | `cold.index` | s | 13.8 / 15.2 | 129 / 141 | 1098 / 1098 | 47% | | `cold.notes_per_s` | notes/s | 72.5 / 106 | 77.6 / 125 | 91.1 / 91.1 | 70% | | `cold.disk_written` | MB | 13.0 / 13.0 | 128 / 128 | 1278 / 1278 | 0% | | `cold.mem_peak` | MB | 14.5 / 14.5 | 33.1 / 33.4 | 203 / 203 | 3% | | `home.first_list` | ms | 34.0 / 37.8 | 202 / 230 | 2465 / 3200 | 68% | | `home.list` | ms | 5.50 / 8.30 | 54.8 / 65.5 | 571 / 705 | 66% | | `journal.catch_up` | ms | 29.1 / 54.0 | 313 / 449 | 4162 / 5329 | 112% | | `journal.entries` | count | 3283 / 5391 | 30655 / 51532 | 307656 / 467343 | 133% | | `open.note` | ms | 43.7 / 51.7 | 41.8 / 47.7 | 26.6 / 46.2 | 113% | | `open.api_get` | ms | 19.9 / 46.6 | 19.6 / 27.5 | 14.4 / 33.7 | 170% | | `open.long_note` | ms | 18.3 / 307 | 250 / 276 | 30.8 / 499 | 1614% | | `sync.round_trip` | ms | 10.4 / 18.4 | 9.22 / 26.9 | 11.8 / 53.7 | 77% | | `sync.save_ack` | ms | 10.3 / 18.5 | 23.9 / 44.5 | 33.9 / 60.5 | 113% | | `storm.save_ack` | ms | 335 / 601 | 312 / 610 | 377 / 803 | 32% | | `storm.edits_per_s` | edits/s | 79.6 / 88.1 | 87.1 / 105 | 74.0 / 90.3 | 47% | | `storm.typing` | s | 126 / 131 | 115 / 135 | 135 / 179 | 51% | | `storm.converge` | ms | 187 / 194 | 179 / 201 | 482 / 688 | 104% | | `storm.disk_written` | MB | 203 / 210 | 202 / 219 | 819 / 862 | 21% | | `storm.outside_edits` | count | 250 / 261 | 229 / 269 | 269 / 356 | 50% | | `storm.dropped_clients` | count | 0.00 / 0.00 | 0.00 / 0.00 | 0.00 / 0.00 | 0% | | `mem.idle` | MB | 10.3 / 10.4 | 10.3 / 10.4 | 10.3 / 10.5 | 2% | | `mem.after_list` | MB | 13.1 / 13.8 | 20.2 / 20.3 | 169 / 169 | 64% | | `mem.after_opens` | MB | 20.9 / 21.4 | 41.3 / 45.6 | 513 / 576 | 37% | | `mem.peak` | MB | 24.7 / 27.8 | 45.0 / 50.3 | 589 / 602 | 22% | | `shutdown` | ms | 26.7 / 48.8 | 24.1 / 45.0 | 66.3 / 87.6 | 100% | Noise is high on single-sample metrics (startup, long note: one sample per run) because every fsync and cold read on this disk is slow and jumpy; the latency distributions (200 to 10,000 samples per run) are steadier (round trip 27-77%, storm ack 19-32%). ### What looks like a real problem 1. **Every start journals a fake `notes.changed` (`by: outside`) for every note never opened.** `watch::changed_on_disk` compares the file hash with history's `base_hash`, which unopened notes don't have. Confirmed in the 10k journal: 50,164 `notes.changed` after 6 starts vs 10,000 `notes.created`. At 100k: 100k file reads + 100k journal rows per restart (470k entries after 6 starts, catch-up 4-5 s), and it probably drives the 600 MB peak and the worse typing latency at 100k. 2. **First-start indexing: ~80-125 notes/s.** 100k notes = 18 min and 1.3 GB written (13 KB/note): one `ids.jsonl` fsync + one journal write per note. 3. **~80-100 keystrokes/s per note, ~20 KB written per keystroke, save ack 300-800 ms under the storm.** Each change is its own `synchronous = FULL` history transaction and the room awaits it before the next message, so nothing is grouped. (#32) 4. **Sync round trip = fsync time** (~10 ms p50, up to 54 ms p95 at 100k): fan-out waits for durable history. (#32) 5. **100k Home:** first `notes.list` 2.5 s, later ones 0.6 s (7 MB answer), 170 MB RSS after listing. Needs paging / background index load. 6. First open of a 50k-word note: 250-500 ms (seed + history write); reopen from history ~20-30 ms. Correctness: the storm (4 clients x 2,500 keystrokes with save checks, outside app rewriting the file every 500 ms, ~250 rewrites per run) never lost or doubled text in 15 runs, all copies converged in ~0.2 s (0.5 s at 100k), file == note after save, no client dropped. Budgets proposed in `docs/perf/budgets.md` / `perf/budgets.json`: gated limits just above today's numbers, targets (not gated yet) for the items above. The browser keystroke-to-paint number is still the existing `@perf` Playwright test (`perf/browser.sh`); running it on a big fixture Home is the next step.
Author
Owner

Perf baseline on current dev (PR #87, replaces #49)

The numbers in my comment above are from dev at 5e727fd. While they ran, #78 (batched startup scan, paged lists) and #83 (fan-out before the disk) landed and fixed four of the six problems listed there, so here is the baseline on dev at e2f4928, which the budgets in docs/perf/budgets.md are now set from.

Same perf VM (4 vCPUs, 7.7 GB, ext4 on a non-rotational disk, no host cache), page cache dropped before every start, nothing else running. 5 warm runs (fresh server each) and 3 cold runs per size; p50/p95 = median over runs of each run's p50/p95; noise = spread of run p50s over their median.

metric unit 1k p50 / p95 10k p50 / p95 100k p50 / p95 worst noise
startup.healthz ms 40.7 / 52.0 32.8 / 35.7 27.3 / 29.0 55%
cold.startup ms 118 / 123 85.0 / 85.3 70.8 / 86.2 42%
cold.first_list ms 160 / 169 205 / 207 760 / 827 30%
cold.index s 0.69 / 0.79 2.70 / 3.23 28.2 / 30.6 32%
cold.notes_per_s notes/s 1449 / 1613 3702 / 4252 3549 / 3584 31%
cold.disk_written MB 2.74 / 2.74 41.2 / 41.2 437 / 438 2%
cold.mem_peak MB 29.6 / 30.4 107 / 111 807 / 821 7%
home.first_page ms 40.6 / 90.0 129 / 185 1121 / 1367 164%
home.page ms 1.66 / 2.79 1.08 / 1.77 3.01 / 4.41 127%
home.page_title ms 1.46 / 1.59 1.05 / 1.24 2.74 / 3.35 142%
home.page_tag ms 2.41 / 2.77 5.91 / 7.44 2.98 / 4.59 60%
home.page_next ms 1.83 / 2.61 1.26 / 1.58 3.16 / 3.74 43%
home.first_list ms 7.60 / 10.1 43.5 / 74.3 420 / 559 79%
home.list ms 6.22 / 14.3 40.6 / 59.3 428 / 574 62%
journal.catch_up ms 10.3 / 12.8 47.3 / 66.4 451 / 539 65%
journal.entries count 1071 / 1142 10062 / 10122 100051 / 100097 13%
open.note ms 51.0 / 80.5 51.0 / 55.2 50.9 / 51.9 12%
open.api_get ms 10.0 / 13.9 9.53 / 16.5 7.78 / 9.09 57%
open.long_note ms 13.6 / 21.2 20.2 / 31.1 27.3 / 35.6 90%
sync.round_trip ms 0.67 / 1.53 0.50 / 0.64 0.49 / 0.65 35%
sync.save_ack ms 9.06 / 16.4 8.53 / 11.3 5.93 / 7.39 24%
storm.save_ack ms 47.0 / 72.7 43.4 / 62.7 42.3 / 48.6 36%
storm.edits_per_s edits/s 637 / 728 734 / 744 888 / 1057 26%
storm.typing s 15.7 / 17.7 13.6 / 16.0 11.3 / 11.8 25%
storm.converge ms 176 / 179 172 / 452 164 / 175 166%
storm.disk_written MB 57.6 / 65.2 55.4 / 61.0 57.5 / 121 127%
storm.outside_edits count 32.0 / 35.0 28.0 / 32.0 23.0 / 24.0 22%
storm.dropped_clients count 0.00 / 0.00 0.00 / 0.00 0.00 / 0.00 0%
mem.idle MB 11.8 / 11.9 12.0 / 12.2 11.9 / 11.9 3%
mem.after_list MB 15.9 / 17.3 27.7 / 28.4 180 / 186 25%
mem.after_opens MB 26.9 / 27.5 78.9 / 86.4 728 / 873 42%
mem.peak MB 31.6 / 35.5 83.1 / 92.8 771 / 941 35%
shutdown ms 48.5 / 57.8 48.0 / 48.7 67.4 / 88.3 63%

Fixed on dev since the first baseline (the harness saw it)

5e727fd e2f4928
first-start indexing, 100k notes 1098 s (91 notes/s) 28 s (3,550 notes/s)
fake notes.changed journaled per unopened note per start 100k per start none
storm keystrokes/s per note 74-87 640-890
storm disk written per 10k keystrokes 200-820 MB 55-58 MB
sync round trip p50 / p95 9-12 / 18-54 ms 0.5 / 0.6-1.5 ms

Still looks like a real problem

  1. Memory at 100k notes: 730-870 MB after opening a few dozen notes, peak up to 940 MB (80 MB at 10k; cold indexing peaks at 820 MB). The jump comes after the startup scan settles (180 MB after listing, then 730 MB). Likely the backlink map, rebuilt from every file on every start and keeping each link's line; not yet verified.
  2. First request at 100k waits 1.1-1.4 s for the Home to open, though Homes open in the background at start; the page itself is 3 ms. 130/185 ms at 10k.
  3. First open of any note is a flat ~51 ms at every Home size (noise 0-12%): a fixed cost, probably several serial fsyncs when the note is first written to history (~9 ms each here).
  4. Keystroke throughput 640-890/s per note (target 1,000), ~5.6 KB written per keystroke (target 50 MB per 10k).
  5. The deprecated whole-Home notes.list is 0.4-0.6 s at 100k (pages: 3-7 ms).

Correctness: the storm (4 clients x 2,500 keystrokes with save checks, outside app rewriting the file every 500 ms) never lost or doubled text in any run on either commit, all copies converged in ~0.2 s, file == note after save, no client dropped. (Two storm failures in my very first run were a harness bug, fixed in 045e021: typing could glue onto an outside line. The saved files had every line exactly once.)

Every gated budget passes on this baseline; the items above are recorded as non-gating targets in perf/budgets.json.

## Perf baseline on current `dev` (PR #87, replaces #49) The numbers in my comment above are from `dev` at 5e727fd. While they ran, #78 (batched startup scan, paged lists) and #83 (fan-out before the disk) landed and fixed four of the six problems listed there, so here is the baseline on `dev` at **e2f4928**, which the budgets in `docs/perf/budgets.md` are now set from. Same perf VM (4 vCPUs, 7.7 GB, ext4 on a non-rotational disk, no host cache), page cache dropped before every start, nothing else running. 5 warm runs (fresh server each) and 3 cold runs per size; p50/p95 = median over runs of each run's p50/p95; noise = spread of run p50s over their median. | metric | unit | 1k p50 / p95 | 10k p50 / p95 | 100k p50 / p95 | worst noise | |---|---|---:|---:|---:|---:| | `startup.healthz` | ms | 40.7 / 52.0 | 32.8 / 35.7 | 27.3 / 29.0 | 55% | | `cold.startup` | ms | 118 / 123 | 85.0 / 85.3 | 70.8 / 86.2 | 42% | | `cold.first_list` | ms | 160 / 169 | 205 / 207 | 760 / 827 | 30% | | `cold.index` | s | 0.69 / 0.79 | 2.70 / 3.23 | 28.2 / 30.6 | 32% | | `cold.notes_per_s` | notes/s | 1449 / 1613 | 3702 / 4252 | 3549 / 3584 | 31% | | `cold.disk_written` | MB | 2.74 / 2.74 | 41.2 / 41.2 | 437 / 438 | 2% | | `cold.mem_peak` | MB | 29.6 / 30.4 | 107 / 111 | 807 / 821 | 7% | | `home.first_page` | ms | 40.6 / 90.0 | 129 / 185 | 1121 / 1367 | 164% | | `home.page` | ms | 1.66 / 2.79 | 1.08 / 1.77 | 3.01 / 4.41 | 127% | | `home.page_title` | ms | 1.46 / 1.59 | 1.05 / 1.24 | 2.74 / 3.35 | 142% | | `home.page_tag` | ms | 2.41 / 2.77 | 5.91 / 7.44 | 2.98 / 4.59 | 60% | | `home.page_next` | ms | 1.83 / 2.61 | 1.26 / 1.58 | 3.16 / 3.74 | 43% | | `home.first_list` | ms | 7.60 / 10.1 | 43.5 / 74.3 | 420 / 559 | 79% | | `home.list` | ms | 6.22 / 14.3 | 40.6 / 59.3 | 428 / 574 | 62% | | `journal.catch_up` | ms | 10.3 / 12.8 | 47.3 / 66.4 | 451 / 539 | 65% | | `journal.entries` | count | 1071 / 1142 | 10062 / 10122 | 100051 / 100097 | 13% | | `open.note` | ms | 51.0 / 80.5 | 51.0 / 55.2 | 50.9 / 51.9 | 12% | | `open.api_get` | ms | 10.0 / 13.9 | 9.53 / 16.5 | 7.78 / 9.09 | 57% | | `open.long_note` | ms | 13.6 / 21.2 | 20.2 / 31.1 | 27.3 / 35.6 | 90% | | `sync.round_trip` | ms | 0.67 / 1.53 | 0.50 / 0.64 | 0.49 / 0.65 | 35% | | `sync.save_ack` | ms | 9.06 / 16.4 | 8.53 / 11.3 | 5.93 / 7.39 | 24% | | `storm.save_ack` | ms | 47.0 / 72.7 | 43.4 / 62.7 | 42.3 / 48.6 | 36% | | `storm.edits_per_s` | edits/s | 637 / 728 | 734 / 744 | 888 / 1057 | 26% | | `storm.typing` | s | 15.7 / 17.7 | 13.6 / 16.0 | 11.3 / 11.8 | 25% | | `storm.converge` | ms | 176 / 179 | 172 / 452 | 164 / 175 | 166% | | `storm.disk_written` | MB | 57.6 / 65.2 | 55.4 / 61.0 | 57.5 / 121 | 127% | | `storm.outside_edits` | count | 32.0 / 35.0 | 28.0 / 32.0 | 23.0 / 24.0 | 22% | | `storm.dropped_clients` | count | 0.00 / 0.00 | 0.00 / 0.00 | 0.00 / 0.00 | 0% | | `mem.idle` | MB | 11.8 / 11.9 | 12.0 / 12.2 | 11.9 / 11.9 | 3% | | `mem.after_list` | MB | 15.9 / 17.3 | 27.7 / 28.4 | 180 / 186 | 25% | | `mem.after_opens` | MB | 26.9 / 27.5 | 78.9 / 86.4 | 728 / 873 | 42% | | `mem.peak` | MB | 31.6 / 35.5 | 83.1 / 92.8 | 771 / 941 | 35% | | `shutdown` | ms | 48.5 / 57.8 | 48.0 / 48.7 | 67.4 / 88.3 | 63% | ### Fixed on dev since the first baseline (the harness saw it) | | 5e727fd | e2f4928 | |---|---:|---:| | first-start indexing, 100k notes | 1098 s (91 notes/s) | 28 s (3,550 notes/s) | | fake `notes.changed` journaled per unopened note per start | 100k per start | none | | storm keystrokes/s per note | 74-87 | 640-890 | | storm disk written per 10k keystrokes | 200-820 MB | 55-58 MB | | sync round trip p50 / p95 | 9-12 / 18-54 ms | 0.5 / 0.6-1.5 ms | ### Still looks like a real problem 1. **Memory at 100k notes: 730-870 MB after opening a few dozen notes, peak up to 940 MB** (80 MB at 10k; cold indexing peaks at 820 MB). The jump comes after the startup scan settles (180 MB after listing, then 730 MB). Likely the backlink map, rebuilt from every file on every start and keeping each link's line; not yet verified. 2. **First request at 100k waits 1.1-1.4 s** for the Home to open, though Homes open in the background at start; the page itself is 3 ms. 130/185 ms at 10k. 3. **First open of any note is a flat ~51 ms at every Home size** (noise 0-12%): a fixed cost, probably several serial fsyncs when the note is first written to history (~9 ms each here). 4. Keystroke throughput 640-890/s per note (target 1,000), ~5.6 KB written per keystroke (target 50 MB per 10k). 5. The deprecated whole-Home `notes.list` is 0.4-0.6 s at 100k (pages: 3-7 ms). Correctness: the storm (4 clients x 2,500 keystrokes with save checks, outside app rewriting the file every 500 ms) never lost or doubled text in any run on either commit, all copies converged in ~0.2 s, file == note after save, no client dropped. (Two storm failures in my very first run were a harness bug, fixed in 045e021: typing could glue onto an outside line. The saved files had every line exactly once.) Every gated budget passes on this baseline; the items above are recorded as non-gating targets in `perf/budgets.json`.
Author
Owner

New targets (kayg, 2026-10-14), replacing the earlier 250 MB goal:

  • Memory: under 100 MiB RSS at 100k notes, then keep pushing lower.
  • Idle CPU: zero. After warm-up there are no periodic wakeups: no polling loops, no ticks, and the watcher is event-driven. Gate: about 0 CPU ticks and under 0.1% over 5 idle minutes, with context switches counted.
  • CPU under load: next to nothing on average with one person typing about 5 chars/s and a second client watching, on the 100k Home.

All three become gates in perf/budgets.json.

**New targets (kayg, 2026-10-14)**, replacing the earlier 250 MB goal: - **Memory:** under 100 MiB RSS at 100k notes, then keep pushing lower. - **Idle CPU:** zero. After warm-up there are no periodic wakeups: no polling loops, no ticks, and the watcher is event-driven. Gate: about 0 CPU ticks and under 0.1% over 5 idle minutes, with context switches counted. - **CPU under load:** next to nothing on average with one person typing about 5 chars/s and a second client watching, on the 100k Home. All three become gates in `perf/budgets.json`.
Author
Owner

#44 fixes: before/after on the perf VM (rebased stack, PRs #191-#200)

Same VM, same fixtures, page cache dropped before each start, 5 warm runs + 3 cold runs per size, idle stretch 300 s once per size after the Home settled, search caught up and rooms closed. before = dev 2a2478c + the harness (#191); after = the whole stack (#200, mimalloc). Same harness binary for both. p50/p95.

metric 1k before → after 10k before → after 100k before → after
home.first_page (ms) 53.1/116 → 13.1/24.0 279/350 → 38.7/54.0 2937/3295 → 60.2/585
open.note (ms) 62.1/103 → 1.10/2.95 65.2/140 → 2.32/8.47 68.4/108 → 4.05/13.7
sync.save_ack (ms) 13.0/60.9 → 5.99/8.15 15.6/67.1 → 9.34/36.6 11.0/39.3 → 12.4/60.1
storm.edits_per_s (/s) 358/513 → 1979/2195 403/486 → 1042/1552 512/601 → 682/978
search.query (ms) 10.1/20.5 → 6.37/15.4 22.0/79.5 → 22.8/79.2 128/455 → 135/478
cold.index (s) 0.76/1.00 → 0.71/1.16 4.63/4.85 → 1.56/1.87 56.0/57.4 → 50.0/54.8
mem.after_search (MB) 33.0/33.6 → 104/128 98.6/117 → 104/114 784/789 → 119/137
mem.peak (MB) 42.6/44.2 → 116/127 104/117 → 120/129 782/790 → 237/257
idle.rss (MB) 46.0/46.0 → 95.8/95.8 135/135 → 118/118 903/903 → 155/155
idle.cpu_pct (%) 0.03/0.03 → 0.00/0.00 0.03/0.03 → 0.00/0.00 0.03/0.03 → 0.00/0.00
idle.wakeups_per_s (/s) 3.99/3.99 → 0.00/0.00 4.00/4.00 → 0.00/0.00 4.00/4.00 → 0.00/0.00
load.typing_cpu_pct (%) 0.78/0.78 → 0.77/0.77 0.87/0.87 → 0.40/0.40 0.80/0.80 → 0.73/0.73

Met

  • First open of a note: 62-68 ms -> 1-4 ms (TCP_NODELAY #192: the flat ~51 ms was the client's delayed ACK; queued seed #193: the history fsync on first open).
  • First request after a restart at 100k: 2.9 s -> 60 ms p50 (#194). p95 is one cold outlier of 585 ms (target 100: not met at p95).
  • Idle: 4 wake-ups/s -> 0, CPU 0.03 % -> 0 at every size (#197: the search writer polled every 250 ms). Typing at 5 chars/s with a watcher: 0.4-0.8 % CPU.
  • Memory at 100k: at rest 903 -> 155 MB, peak 782 -> 237-257 MB, after search 784 -> 119 MB (#195 links in SQLite, #198 search caches, #199 mimalloc, #200 compact index). Heap at rest is ~30 MB (heaptrack); local quiet measurements give 52-54 MB settled, 85-102 MB after searches.
  • Cold index at 100k: 56 -> 50 s (after fixing the 6x regression links-in-SQLite first caused, #195).

Not met / open

  • RSS at 100k under 100 MB: 155 MB at rest after the full harness (storm, whole-list x21, journal, search) on the VM. Live heap is ~30 MB; the rest is allocator retention after bursts. Next: stream the deprecated whole list, shrink the search reconcile (17 MB of stamps per start) and query buffers.
  • mimalloc costs small Homes: idle 46 -> 96 MB at 1k, 135 -> 118 at 10k. Decision to confirm on #199.
  • search.query p95 ~460 ms at 100k (unchanged, budget 100) and the first search build takes ~2 min at 100k on the VM (search.catch_up): search's own work, not touched here.
  • Possible lost outside edit on dev: in 1 of 5 storm runs at 100k on the before build, one of ~35 outside rewrites ("Outside line 12") never appeared in the note (all clients and the server agreed without it; lines 11 and 13 are there). Not seen in any after run or in the 15 earlier runs. Worth an issue: an outside rewrite racing a save, probably.
## #44 fixes: before/after on the perf VM (rebased stack, PRs #191-#200) Same VM, same fixtures, page cache dropped before each start, 5 warm runs + 3 cold runs per size, idle stretch 300 s once per size after the Home settled, search caught up and rooms closed. **before** = `dev` 2a2478c + the harness (#191); **after** = the whole stack (#200, mimalloc). Same harness binary for both. p50/p95. | metric | 1k before → after | 10k before → after | 100k before → after | |---|---|---|---| | `home.first_page` (ms) | 53.1/116 → 13.1/24.0 | 279/350 → 38.7/54.0 | 2937/3295 → 60.2/585 | | `open.note` (ms) | 62.1/103 → 1.10/2.95 | 65.2/140 → 2.32/8.47 | 68.4/108 → 4.05/13.7 | | `sync.save_ack` (ms) | 13.0/60.9 → 5.99/8.15 | 15.6/67.1 → 9.34/36.6 | 11.0/39.3 → 12.4/60.1 | | `storm.edits_per_s` (/s) | 358/513 → 1979/2195 | 403/486 → 1042/1552 | 512/601 → 682/978 | | `search.query` (ms) | 10.1/20.5 → 6.37/15.4 | 22.0/79.5 → 22.8/79.2 | 128/455 → 135/478 | | `cold.index` (s) | 0.76/1.00 → 0.71/1.16 | 4.63/4.85 → 1.56/1.87 | 56.0/57.4 → 50.0/54.8 | | `mem.after_search` (MB) | 33.0/33.6 → 104/128 | 98.6/117 → 104/114 | 784/789 → 119/137 | | `mem.peak` (MB) | 42.6/44.2 → 116/127 | 104/117 → 120/129 | 782/790 → 237/257 | | `idle.rss` (MB) | 46.0/46.0 → 95.8/95.8 | 135/135 → 118/118 | 903/903 → 155/155 | | `idle.cpu_pct` (%) | 0.03/0.03 → 0.00/0.00 | 0.03/0.03 → 0.00/0.00 | 0.03/0.03 → 0.00/0.00 | | `idle.wakeups_per_s` (/s) | 3.99/3.99 → 0.00/0.00 | 4.00/4.00 → 0.00/0.00 | 4.00/4.00 → 0.00/0.00 | | `load.typing_cpu_pct` (%) | 0.78/0.78 → 0.77/0.77 | 0.87/0.87 → 0.40/0.40 | 0.80/0.80 → 0.73/0.73 | **Met** - First open of a note: 62-68 ms -> 1-4 ms (TCP_NODELAY #192: the flat ~51 ms was the client's delayed ACK; queued seed #193: the history fsync on first open). - First request after a restart at 100k: 2.9 s -> 60 ms p50 (#194). p95 is one cold outlier of 585 ms (target 100: not met at p95). - Idle: 4 wake-ups/s -> 0, CPU 0.03 % -> 0 at every size (#197: the search writer polled every 250 ms). Typing at 5 chars/s with a watcher: 0.4-0.8 % CPU. - Memory at 100k: at rest 903 -> 155 MB, peak 782 -> 237-257 MB, after search 784 -> 119 MB (#195 links in SQLite, #198 search caches, #199 mimalloc, #200 compact index). Heap at rest is ~30 MB (heaptrack); local quiet measurements give 52-54 MB settled, 85-102 MB after searches. - Cold index at 100k: 56 -> 50 s (after fixing the 6x regression links-in-SQLite first caused, #195). **Not met / open** - RSS at 100k under 100 MB: 155 MB at rest *after* the full harness (storm, whole-list x21, journal, search) on the VM. Live heap is ~30 MB; the rest is allocator retention after bursts. Next: stream the deprecated whole list, shrink the search reconcile (17 MB of stamps per start) and query buffers. - mimalloc costs small Homes: idle 46 -> 96 MB at 1k, 135 -> 118 at 10k. Decision to confirm on #199. - `search.query` p95 ~460 ms at 100k (unchanged, budget 100) and the first search build takes ~2 min at 100k on the VM (`search.catch_up`): search's own work, not touched here. - **Possible lost outside edit on dev**: in 1 of 5 storm runs at 100k on the *before* build, one of ~35 outside rewrites ("Outside line 12") never appeared in the note (all clients and the server agreed without it; lines 11 and 13 are there). Not seen in any *after* run or in the 15 earlier runs. Worth an issue: an outside rewrite racing a save, probably.
Author
Owner

#44 perf VM, rounds 11 and 13: search, memory, and the cold index at 100k

Machine: perf VM, 4 CPUs, 7.7 GiB. Every run drops caches. Numbers are p50 / p95.

The build sets in the table:

  • dev: dev 583c46e, round 11, 5 runs, dev's harness.
  • all4: all4 = #227 + #314 + #315 + #316, re-run in round 13 with #291's harness so it compares fairly with all5. #291 measures search after the index has caught up.
  • all5: all4 + #338 + #339 + #340.
  • all5, no whole list: the same build with the harness's 21 deprecated whole-Home notes.list calls left out (PERF_NO_WHOLE_LIST=1, VM-only).

Rounds 13 and later take flock /root/perf-vm.lock (with -o, so servers never inherit it).

100k notes

metric target dev (r11) all4 all5 all5, no whole list
search.query p50 < 15, p95 < 50 81.7 / 298 39.9 / 73.3 5.78 / 88.9 5.97 / 29.3
search.first_query n/a 373 / 738 114 / 233 83.5 / 174
idle.rss MB < 100 325 173 153 114
mem.peak MB < 150 369 / 386 487 / 494 477 / 482 123 / 175
mem.after_opens MB 285 / 323 473 / 483 442 / 466 48.6 / 48.7
home.first_page ms p95 < 50 24 / 290 91 / 158 78 / 196 87 / 224
open.note ms p95 < 5 1.17 / 2.77 1.79 / 4.09 1.80 / 4.43 3.78 / 8.68
sync.save_ack ms p95 < 15 7.39 / 12.9 10.7 / 37.7 11.6 / 33.3 11.7 / 20.8
cold.index s ≪ 50 48.9 36.9 58.8 43.2
cold.disk_written MB 4,010 3,470 3,470 3,520
idle CPU, wake-ups/s 0 0, 0 0, 0 0, 0 0, 0

At 1k and 10k, all5 gives:

  • search.query 5.2 / 15.8 (1k) and 6.9 / 40.2 (10k);
  • idle.rss 42 MB (1k) and 58 MB (10k).

save_ack and cold.index moved for all4 between round 11 and round 13 with the same binary (r11: 5.94 / 7.88 and 41.5 s). They are noisy across rounds, so compare within a round.

What I found and what changed

  1. Search: 9–34 ms of search work per query → 0.7–3.9 ms. Measured with the harness queries against the 100k index; on the VM, p50 is 39.9 → 5.8 ms. Three independent PRs, each on top of #315:
    • #338: the "recently used" lookup joined all 100,000 items to the used ones. That was 8–16 ms of every search, even with nothing used yet. It is now a CROSS JOIN plus an index on frecency(at).
    • #339: title matches get their own small FTS5 index, titles (contentless, about 3 MB at 100k). A title lookup goes from 3–11 ms to under 1 ms; the first keystroke goes from 8 ms to 0.7 ms. Existing indexes fill it on open in 0.25 s, with no rebuild.
    • #340: words of four letters or more are looked up as whole words first. FTS5 has to merge the whole list of a prefix (coffee*) before it answers, which takes 7–25 ms per common word. A whole word stops after the newest 150 matches, in under 0.5 ms. The prefix form still runs when that finds too few, so a word still being typed is found.
  2. Memory: the deprecated whole-Home notes.list makes most of the peak and the leftover. Without it, after_opens drops from 442 to 49 MB and the peak from 477 to 123 MB (p50). It builds a serde_json::Value of 100,000 objects per call (Outcome::new → to_value), and the harness calls it 21 times. Question for kayg: its description says "deprecated; for one release". Can it go now? The web app already pages (limit: 500). If it has to stay, I'll make it cheap instead.
  3. Memory: transparent huge pages. The VM, like Debian by default, has THP always with max_ptes_none 511. Sampling the server's memory map every 20 s showed RSS growing while idle, 126 → 155 MB, as AnonHugePages went 31 → 84 MB. The kernel merges thinned-out heap into 2 MB pages that trimming can't return. #358 (on top of #314) turns THP off for the process with prctl(PR_SET_THP_DISABLE). That is a second unsafe call in calternal-memory and needs a nod.
  4. Cold index: 3.5 GB written for a 240 MB list store. The list store's eight secondary indexes have random keys, and they were rewritten on every 4,096-note batch. #372 (based on dev) fills an empty store without them and builds them once at the end. A replay of the real 100k fill: 3,966 → 1,274 MB written, in about a third of the time.
  5. First page after a start is 60–220 ms on dropped caches at every size, and the slow run varies. It isn't the search build. Round 16 is probing it: a delayed or skipped background open of the Home, at 10k and 100k. Next comment.

Next: round 15 (all6 = all5 + #358 + #372, with and without the whole list), round 16 (first page), and a heap profile of a warm 100k run without the whole list, to find what still keeps idle at about 100 MB.

## #44 perf VM, rounds 11 and 13: search, memory, and the cold index at 100k Machine: perf VM, 4 CPUs, 7.7 GiB. Every run drops caches. Numbers are p50 / p95. The build sets in the table: - **dev**: dev 583c46e, round 11, 5 runs, dev's harness. - **all4**: all4 = #227 + #314 + #315 + #316, re-run in round 13 with #291's harness so it compares fairly with all5. #291 measures search after the index has caught up. - **all5**: all4 + #338 + #339 + #340. - **all5, no whole list**: the same build with the harness's 21 deprecated whole-Home `notes.list` calls left out (`PERF_NO_WHOLE_LIST=1`, VM-only). Rounds 13 and later take `flock /root/perf-vm.lock` (with `-o`, so servers never inherit it). ### 100k notes | metric | target | dev (r11) | all4 | all5 | all5, no whole list | |---|---|---|---|---|---| | search.query | p50 < 15, p95 < 50 | 81.7 / 298 | 39.9 / 73.3 | **5.78** / 88.9 | **5.97 / 29.3** | | search.first_query | | n/a | 373 / 738 | 114 / 233 | 83.5 / 174 | | idle.rss MB | < 100 | 325 | 173 | 153 | 114 | | mem.peak MB | < 150 | 369 / 386 | 487 / 494 | 477 / 482 | **123** / 175 | | mem.after_opens MB | | 285 / 323 | 473 / 483 | 442 / 466 | **48.6** / 48.7 | | home.first_page ms | p95 < 50 | 24 / 290 | 91 / 158 | 78 / 196 | 87 / 224 | | open.note ms | p95 < 5 | 1.17 / 2.77 | 1.79 / 4.09 | 1.80 / 4.43 | 3.78 / 8.68 | | sync.save_ack ms | p95 < 15 | 7.39 / 12.9 | 10.7 / 37.7 | 11.6 / 33.3 | 11.7 / 20.8 | | cold.index s | ≪ 50 | 48.9 | 36.9 | 58.8 | 43.2 | | cold.disk_written MB | | 4,010 | 3,470 | 3,470 | 3,520 | | idle CPU, wake-ups/s | 0 | 0, 0 | 0, 0 | 0, 0 | 0, 0 | At 1k and 10k, all5 gives: - search.query 5.2 / 15.8 (1k) and 6.9 / 40.2 (10k); - idle.rss 42 MB (1k) and 58 MB (10k). `save_ack` and `cold.index` moved for all4 between round 11 and round 13 with the same binary (r11: 5.94 / 7.88 and 41.5 s). They are noisy across rounds, so compare within a round. ### What I found and what changed 1. **Search: 9–34 ms of search work per query → 0.7–3.9 ms.** Measured with the harness queries against the 100k index; on the VM, p50 is 39.9 → 5.8 ms. Three independent PRs, each on top of #315: - **#338**: the "recently used" lookup joined all 100,000 items to the used ones. That was 8–16 ms of every search, even with nothing used yet. It is now a `CROSS JOIN` plus an index on `frecency(at)`. - **#339**: title matches get their own small FTS5 index, `titles` (contentless, about 3 MB at 100k). A title lookup goes from 3–11 ms to under 1 ms; the first keystroke goes from 8 ms to 0.7 ms. Existing indexes fill it on open in 0.25 s, with no rebuild. - **#340**: words of four letters or more are looked up as whole words first. FTS5 has to merge the whole list of a prefix (`coffee*`) before it answers, which takes 7–25 ms per common word. A whole word stops after the newest 150 matches, in under 0.5 ms. The prefix form still runs when that finds too few, so a word still being typed is found. 2. **Memory: the deprecated whole-Home `notes.list` makes most of the peak and the leftover.** Without it, after_opens drops from 442 to 49 MB and the peak from 477 to 123 MB (p50). It builds a `serde_json::Value` of 100,000 objects per call (`Outcome::new` → `to_value`), and the harness calls it 21 times. **Question for kayg:** its description says "deprecated; for one release". Can it go now? The web app already pages (`limit: 500`). If it has to stay, I'll make it cheap instead. 3. **Memory: transparent huge pages.** The VM, like Debian by default, has THP `always` with `max_ptes_none` 511. Sampling the server's memory map every 20 s showed RSS *growing while idle*, 126 → 155 MB, as `AnonHugePages` went 31 → 84 MB. The kernel merges thinned-out heap into 2 MB pages that trimming can't return. **#358** (on top of #314) turns THP off for the process with `prctl(PR_SET_THP_DISABLE)`. That is a second `unsafe` call in `calternal-memory` and **needs a nod**. 4. **Cold index: 3.5 GB written for a 240 MB list store.** The list store's eight secondary indexes have random keys, and they were rewritten on every 4,096-note batch. **#372** (based on dev) fills an empty store without them and builds them once at the end. A replay of the real 100k fill: 3,966 → 1,274 MB written, in about a third of the time. 5. **First page after a start** is 60–220 ms on dropped caches at every size, and the slow run varies. It isn't the search build. Round 16 is probing it: a delayed or skipped background open of the Home, at 10k and 100k. Next comment. Next: round 15 (all6 = all5 + #358 + #372, with and without the whole list), round 16 (first page), and a heap profile of a warm 100k run without the whole list, to find what still keeps idle at about 100 MB.
Author
Owner

#44 perf VM, round 15: no huge pages (#358) and the cold fill (#372)

all6 = all5 + #358 + #372: #227, #314, #315, #316, #338, #339, #340, #358, #372. Same harness and setup as round 13 (#291 harness, 3 runs, dropped caches, under the VM lock). Numbers are p50 / p95.

100k notes

metric target all5 (r13) all6 all5, no whole list (r13) all6, no whole list
idle.rss MB < 100 153 102 114 92.4
mem.peak MB < 150 477 / 482 451 / 473 123 / 175 140 / 150
search.query ms p50 < 15, p95 < 50 5.78 / 88.9 5.70 / 36.3 5.97 / 29.3 5.62 / 19.5
search.first_query ms 114 / 233 73 / 201 83.5 / 174 93 / 250
home.first_page ms p95 < 50 78 / 196 49 / 88 87 / 224 45 / 54
open.note ms p95 < 5 1.80 / 4.43 3.73 / 5.30 3.78 / 8.68 3.06 / 9.17
sync.save_ack ms p95 < 15 11.6 / 33.3 14.1 / 30.3 11.7 / 20.8 7.86 / 17.9
cold.index s ≪ 50 58.8 23.3 43.2 28.8
cold.disk_written MB 3,470 1,010 3,520 1,050
cold.mem_peak MB 462 529 520 528
idle CPU, wake-ups/s 0 0, 0 0, 0 0, 0 0, 0

At 1k / 10k, all6 gives:

  • search.query 5.2 / 14.8 and 6.1 / 17.2;
  • idle.rss 40 and 57 MB;
  • cold.index 0.58 and 2.0 s.

Where things stand

  • cold.index: done. #372 takes it to 23–29 s at 100k (from 37–59 s) and cuts cold writes 3.5 GB → 1.0 GB.
  • search.query: done at every size. Its p95 is lower without the whole-list calls, which leave the heap and CPU busy.
  • idle.rss: 92 MB without the whole list, 102 MB with it. #358 is worth about 40–50 MB at 100k, which is a free win.
  • mem.peak: 140 / 150 without the whole list. With it, about 450 MB: the deprecated whole-Home notes.list builds a serde_json::Value of 100,000 objects per call. I'd like to remove it (its description says "for one release"; the web app already pages). The alternative is to stream it without the Value. Which would kayg prefer?
  • cold.mem_peak, 529 MB, is next. A heap profile of a cold 100k fill is queued (round 18).
  • home.first_page: right after a start on dropped caches it varies run to run, 11–88 ms. A standalone probe (round 16) gets 12–47 ms with or without the background Home open, so it isn't simply that. Round 17 times the parts inside the server.
  • open.note p95 is 5–9 ms at 100k when it runs during the warm scan right after a start (without the whole-list calls, it comes about 10 s earlier). Looking at it next.
  • sync.save_ack overlaps with #298 (history commit p99), so I'm leaving it to that work.

New since the last comment: #382, a small PR that cuts the list store's WAL back to 8 MB after checkpoints. It had grown to 127 MB next to a 240 MB meta.db.

## #44 perf VM, round 15: no huge pages (#358) and the cold fill (#372) **all6** = all5 + #358 + #372: #227, #314, #315, #316, #338, #339, #340, #358, #372. Same harness and setup as round 13 (#291 harness, 3 runs, dropped caches, under the VM lock). Numbers are p50 / p95. ### 100k notes | metric | target | all5 (r13) | **all6** | all5, no whole list (r13) | **all6, no whole list** | |---|---|---|---|---|---| | idle.rss MB | < 100 | 153 | **102** | 114 | **92.4** | | mem.peak MB | < 150 | 477 / 482 | 451 / 473 | 123 / 175 | **140 / 150** | | search.query ms | p50 < 15, p95 < 50 | 5.78 / 88.9 | **5.70 / 36.3** | 5.97 / 29.3 | **5.62 / 19.5** | | search.first_query ms | | 114 / 233 | 73 / 201 | 83.5 / 174 | 93 / 250 | | home.first_page ms | p95 < 50 | 78 / 196 | 49 / 88 | 87 / 224 | 45 / 54 | | open.note ms | p95 < 5 | 1.80 / 4.43 | 3.73 / 5.30 | 3.78 / 8.68 | 3.06 / 9.17 | | sync.save_ack ms | p95 < 15 | 11.6 / 33.3 | 14.1 / 30.3 | 11.7 / 20.8 | 7.86 / 17.9 | | cold.index s | ≪ 50 | 58.8 | **23.3** | 43.2 | **28.8** | | cold.disk_written MB | | 3,470 | **1,010** | 3,520 | **1,050** | | cold.mem_peak MB | | 462 | 529 | 520 | 528 | | idle CPU, wake-ups/s | 0 | 0, 0 | 0, 0 | 0, 0 | 0, 0 | At 1k / 10k, all6 gives: - search.query 5.2 / 14.8 and 6.1 / 17.2; - idle.rss 40 and 57 MB; - cold.index 0.58 and 2.0 s. ### Where things stand - **cold.index: done.** #372 takes it to 23–29 s at 100k (from 37–59 s) and cuts cold writes 3.5 GB → 1.0 GB. - **search.query: done** at every size. Its p95 is lower without the whole-list calls, which leave the heap and CPU busy. - **idle.rss**: 92 MB without the whole list, 102 MB with it. #358 is worth about 40–50 MB at 100k, which is a free win. - **mem.peak**: 140 / 150 without the whole list. With it, about 450 MB: the deprecated whole-Home `notes.list` builds a `serde_json::Value` of 100,000 objects per call. **I'd like to remove it** (its description says "for one release"; the web app already pages). The alternative is to stream it without the `Value`. Which would kayg prefer? - **cold.mem_peak**, 529 MB, is next. A heap profile of a cold 100k fill is queued (round 18). - **home.first_page**: right after a start on dropped caches it varies run to run, 11–88 ms. A standalone probe (round 16) gets 12–47 ms with or without the background Home open, so it isn't simply that. Round 17 times the parts inside the server. - **open.note** p95 is 5–9 ms at 100k when it runs during the warm scan right after a start (without the whole-list calls, it comes about 10 s earlier). Looking at it next. - **sync.save_ack** overlaps with #298 (history commit p99), so I'm leaving it to that work. New since the last comment: **#382**, a small PR that cuts the list store's WAL back to 8 MB after checkpoints. It had grown to 127 MB next to a 240 MB `meta.db`.
Author
Owner

#44 perf VM, rounds 17–21: first page, two heaps, and where it stands

New PRs

PR what evidence
#384 (replaces #372) cold fill without the list's random-key indexes; keeps notes_updated so the app's pages stay indexed while a cold Home fills without that index, pages sorted the whole store while filling (5–94 ms each)
#382 list store WAL cut back to 8 MB after checkpoints a 127 MB meta.db-wal sat beside a 240 MB store
#385 shutdown checkpoints (TRUNCATE) every list store the stores stay open until exit, so the next start read the whole log back first
#386 (on #358) two allocator heaps for the whole server: mallopt(M_ARENA_MAX, 2) before the runtime starts see below; a third unsafe call in calternal-memory, needs a nod
#388 a cold open keeps its 100k announcements compact until recorded 85.5 → 22.8 MB held at once

Round 17: timing probes inside the server, 100k, dropped caches. A 41 ms first page was:

  • 27 ms opening the list store, which was reading back a 42 MB WAL left by the previous run;
  • 6.7 ms in the page query;
  • 5.5 ms opening the engine runtime.

#385 fixes the first part. Round 20 (all6 + #384, #382, #385) gave home.first_page at 100k of 49 / 88 → 17.9 / 22.6 ms, at 10k 36 / 62 → 10.6 / 11.7, and at 1k 16 / 53 → 8.0 / 9.4.

Round 19: the same binary with glibc.malloc.arena_max=2. idle.rss 102 → 80 MB, peak 451 → 263 MB, cold peak 529 → 304 MB, and no request got slower. #386 makes it part of the server.

100k now: all8 = every open #44 PR (round 21, 3 runs)

all8 is #227, #314, #315, #316, #338, #339, #340, #358, #382, #384, #385, #386. Numbers are p50 / p95.

metric target dev (r11) all8 all8, no whole list
search.query ms p50 < 15, p95 < 50 81.7 / 298* 6.27 / 28.5 4.74 / 38.8
idle.rss MB < 100 325 78.9 65.6
mem.peak MB < 150 369 / 386 269 / 275 111 / 120
cold.mem_peak MB 494 300 293
home.first_page ms p95 < 50 24 / 290 33 / 82 27.5 / 48.9
open.note ms p95 < 5 1.17 / 2.77 1.66 / 3.81 1.72 / 3.41
sync.save_ack ms p95 < 15 7.39 / 12.9 8.93 / 34.7 6.10 / 15.0
cold.index s ≪ 50 48.9 25.0 25.3
cold.disk_written MB 4,010 1,220 1,220
idle CPU, wake-ups/s 0 0, 0 0, 0 0, 0

* dev's harness measured search during the index's first build. With #291's harness, all4 was 39.9 / 73.3.

At 1k / 10k, all8 gives:

  • idle.rss 33 / 44 MB;
  • peak 40 / 56 MB;
  • search.query 5.5 / 11.6 and 6.3 / 16.2.

This round was noisy at the small sizes: first_page 47 / 72 at 1k, against 8 / 9 for all7 in round 20. Round 23 is running an interleaved A/B of all7 vs all8 (5 runs, 1k and 10k) to check that two heaps cost no latency.

Open questions

  1. The deprecated whole-Home notes.list is the last big memory item: peak 269 MB with it, 111 MB without. Remove it now, or should I make it stream without the serde_json::Value tree?
  2. Opening notes with long histories. A room rebuilds a note by replaying every update since it was created. That costs about 2.2 µs per update locally, so a daily note typed all day (5,000 updates) takes 11 ms, and 20,000 updates take 52 ms. That breaks open.note's 5 ms target for real use, though not for the fixture. The fix is history snapshots: a merged state stored every N updates, with opens replaying only what comes after it. Versions would still replay prefixes from the nearest earlier snapshot. That lives in history.rs, next to #298's work. Should I do it, or coordinate with #298?
  3. sync.save_ack p95 swings 13–35 ms between rounds with the same binary. I'm leaving it to #298.
## #44 perf VM, rounds 17–21: first page, two heaps, and where it stands ### New PRs | PR | what | evidence | |---|---|---| | **#384** (replaces #372) | cold fill without the list's random-key indexes; keeps `notes_updated` so the app's pages stay indexed while a cold Home fills | without that index, pages sorted the whole store while filling (5–94 ms each) | | **#382** | list store WAL cut back to 8 MB after checkpoints | a 127 MB `meta.db-wal` sat beside a 240 MB store | | **#385** | shutdown checkpoints (TRUNCATE) every list store | the stores stay open until exit, so the next start read the whole log back first | | **#386** (on #358) | two allocator heaps for the whole server: `mallopt(M_ARENA_MAX, 2)` before the runtime starts | see below; a third `unsafe` call in calternal-memory, **needs a nod** | | **#388** | a cold open keeps its 100k announcements compact until recorded | 85.5 → 22.8 MB held at once | **Round 17**: timing probes inside the server, 100k, dropped caches. A 41 ms first page was: - 27 ms opening the list store, which was reading back a 42 MB WAL left by the previous run; - 6.7 ms in the page query; - 5.5 ms opening the engine runtime. **#385** fixes the first part. Round 20 (all6 + #384, #382, #385) gave `home.first_page` at 100k of 49 / 88 → **17.9 / 22.6 ms**, at 10k 36 / 62 → 10.6 / 11.7, and at 1k 16 / 53 → 8.0 / 9.4. **Round 19**: the same binary with `glibc.malloc.arena_max=2`. idle.rss 102 → 80 MB, peak 451 → 263 MB, cold peak 529 → 304 MB, and no request got slower. #386 makes it part of the server. ### 100k now: all8 = every open #44 PR (round 21, 3 runs) all8 is #227, #314, #315, #316, #338, #339, #340, #358, #382, #384, #385, #386. Numbers are p50 / p95. | metric | target | dev (r11) | **all8** | **all8, no whole list** | |---|---|---|---|---| | search.query ms | p50 < 15, p95 < 50 | 81.7 / 298* | **6.27 / 28.5** | **4.74 / 38.8** | | idle.rss MB | < 100 | 325 | **78.9** | **65.6** | | mem.peak MB | < 150 | 369 / 386 | 269 / 275 | **111 / 120** | | cold.mem_peak MB | | 494 | 300 | 293 | | home.first_page ms | p95 < 50 | 24 / 290 | 33 / 82 | 27.5 / 48.9 | | open.note ms | p95 < 5 | 1.17 / 2.77 | **1.66 / 3.81** | **1.72 / 3.41** | | sync.save_ack ms | p95 < 15 | 7.39 / 12.9 | 8.93 / 34.7 | 6.10 / 15.0 | | cold.index s | ≪ 50 | 48.9 | **25.0** | **25.3** | | cold.disk_written MB | | 4,010 | 1,220 | 1,220 | | idle CPU, wake-ups/s | 0 | 0, 0 | **0, 0** | **0, 0** | \* dev's harness measured search during the index's first build. With #291's harness, all4 was 39.9 / 73.3. At 1k / 10k, all8 gives: - idle.rss 33 / 44 MB; - peak 40 / 56 MB; - search.query 5.5 / 11.6 and 6.3 / 16.2. This round was noisy at the small sizes: first_page 47 / 72 at 1k, against 8 / 9 for all7 in round 20. Round 23 is running an interleaved A/B of all7 vs all8 (5 runs, 1k and 10k) to check that two heaps cost no latency. ### Open questions 1. **The deprecated whole-Home `notes.list`** is the last big memory item: peak 269 MB with it, 111 MB without. Remove it now, or should I make it stream without the `serde_json::Value` tree? 2. **Opening notes with long histories.** A room rebuilds a note by replaying every update since it was created. That costs about 2.2 µs per update locally, so a daily note typed all day (5,000 updates) takes 11 ms, and 20,000 updates take 52 ms. That breaks open.note's 5 ms target for real use, though not for the fixture. The fix is history snapshots: a merged state stored every N updates, with opens replaying only what comes after it. Versions would still replay prefixes from the nearest earlier snapshot. That lives in `history.rs`, next to #298's work. Should I do it, or coordinate with #298? 3. **sync.save_ack p95** swings 13–35 ms between rounds with the same binary. I'm leaving it to #298.
Author
Owner

#44 perf VM, rounds 22–25: a short follow-up

  • Two heaps (#386), latency A/B (round 23): all7 and all8 interleaved, 1k and 10k, 5 runs each, done twice. No request got slower and the peak is lower; table on #386.

  • #388 closed. Compact cold-open events didn't move cold.mem_peak at 100k (300 → 300 MB). An 8 MB page cache for the fresh fill didn't either, so it was never opened as a PR.

  • Where the cold peak comes from (round 25, RSS sampled every 0.5 s during a cold 100k open with every PR):

    • It is all anonymous memory; file-backed RSS stays at about 14.5 MB.
    • Reading ids takes it to 50 MB.
    • Just before the list fill starts it jumps to 153 MB.
    • It climbs to 229 MB while the fill runs.
    • Right after the last row it peaks at 292 MB, then drops back to 205.
    • A 10k heap profile peaks at only 32 MB of heap (20 MB of it SQLite's page cache), so most of the cold RSS isn't live data held at once.

    This is the one memory number still well above 150 MB. It happens once per Home, on its first open. A 100k heap profile needs more than heaptrack can do on this VM in reasonable time, so I've left it for now.

Every #44 PR, its base, and what it's measured to do are listed in the round 17–21 comment above.

## #44 perf VM, rounds 22–25: a short follow-up - **Two heaps (#386), latency A/B** (round 23): all7 and all8 interleaved, 1k and 10k, 5 runs each, done twice. No request got slower and the peak is lower; table on #386. - **#388 closed.** Compact cold-open events didn't move `cold.mem_peak` at 100k (300 → 300 MB). An 8 MB page cache for the fresh fill didn't either, so it was never opened as a PR. - **Where the cold peak comes from** (round 25, RSS sampled every 0.5 s during a cold 100k open with every PR): - It is all anonymous memory; file-backed RSS stays at about 14.5 MB. - Reading ids takes it to 50 MB. - Just before the list fill starts it jumps to 153 MB. - It climbs to 229 MB while the fill runs. - Right after the last row it peaks at 292 MB, then drops back to 205. - A 10k heap profile peaks at only 32 MB of heap (20 MB of it SQLite's page cache), so most of the cold RSS isn't live data held at once. This is the one memory number still well above 150 MB. It happens once per Home, on its first open. A 100k heap profile needs more than heaptrack can do on this VM in reasonable time, so I've left it for now. Every #44 PR, its base, and what it's measured to do are listed in the round 17–21 comment above.
kayg referenced this issue from a commit 2026-10-15 02:22:45 +00:00
Author
Owner

Live 02:25 IST: train j (#391, dev a305ee2). Contains the #44 server speed PRs #227 #291 #315 #316 #338 #339 #340 #382 #384 #385, plus #389 (the #387 test). fmt/clippy/workspace tests clean; e2e 160 passed, 0 failed; no errors in the server log after the start. Held for kayg: #314, #358, #386 (questions 4 and 5 above).

Live 02:25 IST: **train j** (#391, dev a305ee2). Contains the #44 server speed PRs #227 #291 #315 #316 #338 #339 #340 #382 #384 #385, plus #389 (the #387 test). fmt/clippy/workspace tests clean; e2e 160 passed, 0 failed; no errors in the server log after the start. Held for kayg: #314, #358, #386 (questions 4 and 5 above).
Author
Owner

#44 memory, continued in #398: where 100k stands now

Perf VM, 100k notes, dropped caches, 3 runs each. Values are p50 / p95. Details, the allocator A/B and the leak soak are on #398.

metric target dev a305ee2 all #398 PRs
idle.rss MB < 50 183 41.9
mem.peak MB < 120 136 / 196 101 / 109
cold.mem_peak MB < 150 587 196
search.query ms p95 < 50 4.88 / 20.0 4.68 / 27.4
open.note ms p95 < 5 1.67 / 3.14 1.41 / 3.07
home.first_page ms p95 < 50 15.8 / 72.4 15.6 / 33.0
idle CPU, wake-ups/s 0 0, 0 0, 0

The PRs:

  • #417: no whole-Home notes.list.
  • #418: arena_max=2 as a tunable in the quadlets. Replaces #386.
  • #427: glibc stays, with trim and no THP. Replaces #314 and #358. mimalloc v2/v3 and jemalloc both lost on idle and cold peak.
  • #428: a compact id index; SQLite caches let go.
  • #429: an 8 MiB cold-fill cache.
  • #435: the leak soak scenario.

Still open: the cold-open peak, and a +7.9 MB idle step between the two soak cycles (dev's step is +24 MB).

## #44 memory, continued in #398: where 100k stands now Perf VM, 100k notes, dropped caches, 3 runs each. Values are p50 / p95. Details, the allocator A/B and the leak soak are on #398. | metric | target | dev a305ee2 | all #398 PRs | |---|---|---|---| | idle.rss MB | < 50 | 183 | **41.9** | | mem.peak MB | < 120 | 136 / 196 | **101 / 109** | | cold.mem_peak MB | < 150 | 587 | 196 | | search.query ms | p95 < 50 | 4.88 / 20.0 | 4.68 / 27.4 | | open.note ms | p95 < 5 | 1.67 / 3.14 | 1.41 / 3.07 | | home.first_page ms | p95 < 50 | 15.8 / 72.4 | 15.6 / 33.0 | | idle CPU, wake-ups/s | 0 | 0, 0 | 0, 0 | The PRs: - **#417**: no whole-Home `notes.list`. - **#418**: `arena_max=2` as a tunable in the quadlets. Replaces #386. - **#427**: glibc stays, with trim and no THP. Replaces #314 and #358. mimalloc v2/v3 and jemalloc both lost on idle and cold peak. - **#428**: a compact id index; SQLite caches let go. - **#429**: an 8 MiB cold-fill cache. - **#435**: the leak soak scenario. Still open: the cold-open peak, and a +7.9 MB idle step between the two soak cycles (dev's step is +24 MB).
Author
Owner

Closing during the 26 Oct handover cleanup: The perf harness is in dev (PRs #340, #384, #408, #418, #444). Memory work continued in #398.

Closing during the 26 Oct handover cleanup: The perf harness is in dev (PRs #340, #384, #408, #418, #444). Memory work continued in #398.
kayg closed this issue 2026-10-26 08:45:58 +00:00
Author
Owner

ADR 0003 evidence migration: docs/perf/budgets.md

Source commit: a4574fea2b107efd11858603c12d6cdab49a5e76; snapshot from dev 55f35fcd. Full original source preserved below before repository removal/stripping. Design, code and test inputs are retained where applicable.

# Perf budgets

Every PR is measured on the perf machine, and a broken budget blocks the merge ([ADR 0005](<../adr/0005-performance-is-a-merge-gate.md>)). This page says what is measured, how, and the limit for each number. The limits the harness checks live in [perf/budgets.json](<../../perf/budgets.json>); keep the two in step.

## How it is measured

- **Machine**: the perf VM (4 vCPUs, 8 GB RAM, HDD Homes and SSD app state, Debian), quiet, used by nothing else while it runs. Its disks have no host cache, and the page cache is emptied before every server start (`--drop-caches`), so every start reads from disk like a fresh boot. The official layout uses existing ext4 `/mnt/b/hdd-ext4` (rotational sdb1) for Homes, matching production ext4, and `/mnt/z4-nvme` (non-rotational sde) for state. Reports identify both filesystems.
- **Homes**: made by `calternal-fixtures`, the same bytes for the same seed: 1,000, 10,000 and 100,000 notes. About 30% daily notes with log entries, the rest regular notes (mostly short, some long, one in 2,000 with 50,000 words), with links, tags, tasks and attachment references.
- **Runs**: `calternal-perf` starts the real `calternal` binary. First on fresh copies of the Home that were never indexed (`cold.*`, 3 runs), then 5 times on the indexed Home, each time a fresh server process.
- **Numbers**: each run gives a p50 and p95 per metric. The report shows the median of those over the runs, plus **noise**: how far the runs' p50s spread, as a percent of their median. A metric measured once per run (startup) pools the runs: p50 is the median run, p95 the slowest. **Max** is the largest observed sample across all runs. Budgets are on p95 unless they say otherwise.
- **Noise band**: a breach with noise over 25% is rerun before it counts (by hand for now; automatic once the gate is wired into PRs).

Run it: `perf/run-vm.sh --sizes 1k,10k,100k --runs 5 --cold-runs 3` (about 40 minutes). Locally: `cargo build --release -p calternal -p calternal-perf`, then `target/release/calternal-perf --bin target/release/calternal --work /tmp/perf --budgets perf/budgets.json` (`--quick` for a smoke test). `--trash-only` runs just the delete, restore and permanent-delete scenario.

The disk side on its own: `storage-bench` (in `crates/perf`) times history commits and note saves straight against the real code on whatever disk it is pointed at, with readers or a big upload going at the same time (#298). For example `storage-bench history --dir /mnt/z4-nvme/b` or `storage-bench save --dir /mnt/z4-nvme/b --upload plain`.

## Budgets

Times are milliseconds unless a unit is given. "All" means every Home size; a size column overrides it.

| metric | budget (all sizes) | at 100k notes | target | gate |
|---|---|---|---|---|
| `startup.healthz` | p95 ≤ 300 | | p95 ≤ 100 | gated |
| `cold.startup` | p95 ≤ 500 | | p95 ≤ 300 | gated |
| `cold.index` (s) | 1k ≤ 5, 10k ≤ 10 | p95 ≤ 60 | | gated |
| `cold.notes_per_s` | | | p50 ≥ 2000 notes/s | target |
| `home.first_page` | p95 ≤ 300 | p95 ≤ 100 | | gated |
| `home.page`, `home.page_title`, `home.page_tag`, `home.page_next` | p95 ≤ 50 | | | gated |
| `search.query` | p95 ≤ 100 | | | gated |
| `search.first_query` | p95 ≤ 1000 | | | target |
| `journal.catch_up` | p95 ≤ 1000 | p95 ≤ 2000 | | gated |
| `open.note` | p95 ≤ 15 | | | gated |
| `open.api_get` | p95 ≤ 50 | | | gated |
| `open.long_note` (50k words) | p95 ≤ 250 | | | gated |
| `sync.round_trip` | p95 ≤ 10 | | | gated |
| `sync.save_ack` | p95 ≤ 40 | | | gated |
| `storm.save_ack` | p95 ≤ 150 | | p95 ≤ 50 | gated |
| `storm.dropped_clients` | 0 | | | gated |
| `storm.converge` | p95 ≤ 2000 | | | gated |
| storm: lost or doubled text | never | | | gated (a failure, not a number) |
| `storm.edits_per_s` | | | p50 ≥ 1000 edits/s | target |
| `storm.disk_written` (10k keystrokes) | | | p95 ≤ 50 MB | target |
| `mem.idle` | p95 ≤ 64 MB | | | gated |
| `mem.peak` | p95 ≤ 256 MB | p95 ≤ 256 MB | | gated (100k: target) |
| `mem.after_opens` | | p95 ≤ 300 MB | | target |
| `shutdown` | p95 ≤ 1000 | | | gated |
| `idle.cpu_pct` | ≤ 0.1 % | | 0 | gated |
| `idle.wakeups_per_s` | ≤ 0.2 /s | | 0 | gated |
| `idle.rss` | | ≤ 100 MB | | gated |
| `load.typing_cpu_pct` | ≤ 2 % | | | gated |
| `soak.idle_ratchet` (MB), `soak.idle_slope` (MB/h) (with `--soak-secs`) | ≤ 5, ≤ 20 | | 0 | target |

The gated limits sit above today's baseline with room for the noise we see (a no-cache disk makes every fsync slow and jumpy); the targets are where we want to be. Tighten a gated limit whenever a change makes the number better, so the gain can't quietly be lost again.

**Gated** budgets block a merge today. **Target** budgets are what we want, but the code doesn't meet them yet; they are reported and become gates when the work that meets them lands (see "Known problems").

## What each metric means

- `startup.healthz`: process start until `/healthz` answers. Startup never waits (ADR 0016), so this must not grow with the Home.
- `home.first_page`: the first request after start, a page of 50 notes; it waits for the Home to open (id index, list store, history).
- `home.page`, `home.page_title`, `home.page_tag`: a page of 50, newest change first, A to Z, and filtered by `#work`. `home.page_next`: 20 pages on through a cursor. `home.page_big`: five pages of 2,000 on through a cursor, the app's background fill (#422).
- `journal.catch_up`: a client that was away reads the whole change journal from the start, 1,000 entries a page (`journal.entries` says how many).
- `open.note`: joining a note's live room until the whole note arrived (what opening a note in the editor waits for), first open in this process.
- `open.api_get`: `notes.get` of a note not open yet.
- `open.long_note`: opening the 50,000-word note.
- `sync.round_trip`: one keystroke from client A until client B has it.
- `sync.save_ack`: one keystroke until the server answers its save check, which is what the editor's "Saved" waits for (history is durable).
- `storm.*`: 4 clients type 10,000 keystrokes into one note, each with a save check, up to 8 unanswered per client; an outside app rewrites the file every 500 ms. Afterwards every copy and the server must agree, every outside line must be there exactly once, and the file must equal the note. `save_ack` is per keystroke under that load, `edits_per_s` the throughput, `converge` the time from the last answer until everyone agrees, `disk_written` the bytes the server wrote, `dropped_clients` clients the server cut off for falling behind.
- `cold.*`: first start on a Home never indexed: `index` is the time until every note is in the id index, `notes_per_s` its rate.
- `mem.idle` / `mem.after_first_page` / `mem.after_opens`: resident memory; `mem.peak` the most at any point in a run.
- `shutdown`: SIGTERM until the process exited (it saves open notes first).
- `idle.*` (first run of each size): once the Home has settled and every room has closed, CPU time (`/proc/<pid>/stat`), thread wake-ups (context switches of every thread, `/proc/<pid>/task/*/status`) and resident memory over `--idle-secs` (300 by default). An idle server must sleep: no polling, no tick timers.
- `soak.*` (first run of each size, only with `--soak-secs N`; `--soak-secs 1800` is the 30-minute leak soak of #398): two cycles, each a third of the time of steady use (pages, a search, two notes opened in the editor and two through the API, ten keystrokes typed and taken out again with a save check, a page of the journal, round after round) and a sixth idle. Memory is sampled every 10 s into `soak-<notes>.tsv` in the work folder. A leak ratchets the idle level up: `idle_ratchet` is the second idle level minus the first (MB). `load_slope` is how fast memory grew under the first load once warm and `idle_slope` how it moved in the second idle stretch after the rooms closed, both in MB per hour. Under load a few hundred sample notes stay open and grow with every keystroke, so the load slope is real use, not a leak by itself; `idle_rss_1` / `idle_rss_2` / `load_rss_max` / `peak` give the levels, `rounds` how much was done.
- `load.typing_*` (first run of each size): one person types five characters a second for a minute, with a save check every five, while a second client watches the same note: the server's CPU share and wake-ups.
- `trash.delete`, `trash.restore`, `trash.forget` (10k notes and up): 30 interleaved API response timings per operation in every warm run. The forget notes are first put in the Trash outside the timed section; each delete is followed by restoring the same note. `trash.forget` measures permanent deletion from the Trash, including its history purge.

## Still to measure

- The web client (boot, keystroke to paint, switching notes, scrolling, bundle size) has its own harness and `web.*` budgets in the same file: [web.md](<web.md>).
- Backlinks. Full-text search is measured by `search.query` and `search.first_query` (ADR 0031).
- Typing latency while a bulk edit runs for the same and another user (ADR 0014).

## Historical all-SSD baseline

2026-10-14, `dev` at e2f4928 plus this harness, on the perf VM (Linux 6.12, 4 vCPUs, 7.7 GB, ext4 on a non-rotational disk without host cache, page cache dropped before every start). 5 warm runs and 3 cold runs per size.

| metric | unit | 1k p50 / p95 | 10k p50 / p95 | 100k p50 / p95 | worst noise |
|---|---|---:|---:|---:|---:|
| `startup.healthz` | ms | 40.7 / 52.0 | 32.8 / 35.7 | 27.3 / 29.0 | 55% |
| `cold.startup` | ms | 118 / 123 | 85.0 / 85.3 | 70.8 / 86.2 | 42% |
| `cold.first_list` | ms | 160 / 169 | 205 / 207 | 760 / 827 | 30% |
| `cold.index` | s | 0.69 / 0.79 | 2.70 / 3.23 | 28.2 / 30.6 | 32% |
| `cold.notes_per_s` | notes/s | 1449 / 1613 | 3702 / 4252 | 3549 / 3584 | 31% |
| `cold.disk_written` | MB | 2.74 / 2.74 | 41.2 / 41.2 | 437 / 438 | 2% |
| `cold.mem_peak` | MB | 29.6 / 30.4 | 107 / 111 | 807 / 821 | 7% |
| `home.first_page` | ms | 40.6 / 90.0 | 129 / 185 | 1121 / 1367 | 164% |
| `home.page` | ms | 1.66 / 2.79 | 1.08 / 1.77 | 3.01 / 4.41 | 127% |
| `home.page_title` | ms | 1.46 / 1.59 | 1.05 / 1.24 | 2.74 / 3.35 | 142% |
| `home.page_tag` | ms | 2.41 / 2.77 | 5.91 / 7.44 | 2.98 / 4.59 | 60% |
| `home.page_next` | ms | 1.83 / 2.61 | 1.26 / 1.58 | 3.16 / 3.74 | 43% |
| `home.first_list` | ms | 7.60 / 10.1 | 43.5 / 74.3 | 420 / 559 | 79% |
| `home.list` | ms | 6.22 / 14.3 | 40.6 / 59.3 | 428 / 574 | 62% |
| `journal.catch_up` | ms | 10.3 / 12.8 | 47.3 / 66.4 | 451 / 539 | 65% |
| `journal.entries` | count | 1071 / 1142 | 10062 / 10122 | 100051 / 100097 | 13% |
| `open.note` | ms | 51.0 / 80.5 | 51.0 / 55.2 | 50.9 / 51.9 | 12% |
| `open.api_get` | ms | 10.0 / 13.9 | 9.53 / 16.5 | 7.78 / 9.09 | 57% |
| `open.long_note` | ms | 13.6 / 21.2 | 20.2 / 31.1 | 27.3 / 35.6 | 90% |
| `sync.round_trip` | ms | 0.67 / 1.53 | 0.50 / 0.64 | 0.49 / 0.65 | 35% |
| `sync.save_ack` | ms | 9.06 / 16.4 | 8.53 / 11.3 | 5.93 / 7.39 | 24% |
| `storm.save_ack` | ms | 47.0 / 72.7 | 43.4 / 62.7 | 42.3 / 48.6 | 36% |
| `storm.edits_per_s` | edits/s | 637 / 728 | 734 / 744 | 888 / 1057 | 26% |
| `storm.typing` | s | 15.7 / 17.7 | 13.6 / 16.0 | 11.3 / 11.8 | 25% |
| `storm.converge` | ms | 176 / 179 | 172 / 452 | 164 / 175 | 166% |
| `storm.disk_written` | MB | 57.6 / 65.2 | 55.4 / 61.0 | 57.5 / 121 | 127% |
| `storm.outside_edits` | count | 32.0 / 35.0 | 28.0 / 32.0 | 23.0 / 24.0 | 22% |
| `storm.dropped_clients` | count | 0.00 / 0.00 | 0.00 / 0.00 | 0.00 / 0.00 | 0% |
| `mem.idle` | MB | 11.8 / 11.9 | 12.0 / 12.2 | 11.9 / 11.9 | 3% |
| `mem.after_list` | MB | 15.9 / 17.3 | 27.7 / 28.4 | 180 / 186 | 25% |
| `mem.after_opens` | MB | 26.9 / 27.5 | 78.9 / 86.4 | 728 / 873 | 42% |
| `mem.peak` | MB | 31.6 / 35.5 | 83.1 / 92.8 | 771 / 941 | 35% |
| `shutdown` | ms | 48.5 / 57.8 | 48.0 / 48.7 | 67.4 / 88.3 | 63% |

Single-value metrics (startup, first page, long note) have one sample per run, so their noise is high; the latency distributions (200 to 10,000 samples per run) are steadier.

An earlier run on `dev` at 5e727fd (before #78 and #83) showed what the harness is for: first-start indexing ran at 80 notes a second (18 minutes for 100k), every start journaled a fake outside change for every note never opened, a note took 80 keystrokes a second at 20 KB of disk writes each, and a keystroke reached the other device only after an fsync (10 ms). All four are fixed on `dev` now (35x, gone, 10x and 20x).

## Known problems the baseline shows

1. **Memory at 100k notes: 730 to 870 MB after opening a few dozen notes, peaks near 940 MB** (80 MB at 10k). It jumps after the startup scan settles, between listing (180 MB) and opening notes. The backlink map, rebuilt from every file on every start and keeping each link's line, is the likely cause; cold indexing peaks at 820 MB as well.
2. **The first request at 100k waits 1.1 to 1.4 s** for the Home to open (id index and list store), though every Home opens in the background at start; the page itself takes 3 ms. 130 ms at 10k.
3. **Opening a note for the first time takes a flat 51 ms at every Home size**, with almost no noise. It doesn't grow with the Home or the note, so it is a fixed cost (most likely several fsyncs in a row while the note is first written to history, about 9 ms each on this disk), worth finding.
4. **One note takes 640 to 890 keystrokes a second** (target 1,000) and the storm writes 55 to 60 MB for 10,000 keystrokes, about 5.6 KB each (target 50 MB).
5. The old whole-Home `notes.list` (deprecated) takes 0.4 to 0.6 s at 100k; the app uses pages, which take 3 to 7 ms at any size. (Removed in #398; `notes.list` without input now returns the first page.)

The storm never lost or doubled text in any run, with 25 to 35 outside rewrites per run, and no client was ever dropped.

## Split storage measurement

`perf/run-vm.sh` runs the full server gate with `--sizes 1k,10k,100k --runs 5
--cold-runs 3 --drop-caches --gate`. It holds `flock -o /root/perf-vm.lock`, waits
for other server/perf processes and uses unique issue-owned roots. Run
`PERF_LAYOUT=ssd PERF_NAME=ssd perf/run-vm.sh` for the same all-SSD comparison.
Harness `--data-dir` controls fixtures and Home copies; `--state-dir` controls
corresponding app stores. `--work` holds other harness output. Cold runs reset both
roots; the first indexed pair is retained together for warm runs.

`sync.save_ack` measures SSD history acknowledgement; `sync.durable_write` measures
an edit through history and explicit `notes.save` completion (HDD atomic file and
directory fsync, excluding the quiet timer). The latter is a separate 30-sample
series after uninterrupted typing samples. `uploads.response` measures completion
of a unique 8 MiB upload; `uploads.round_trip` and `uploads.save_ack` measure 200
keystrokes while those uploads run. These new observations have no blocking limit
until measured; existing budgets are unchanged. Web/browser gates use
`perf/web.sh --data-dir HDD --state-dir SSD --gate` and the same all-SSD comparison;
they and optional soak targets have their own runners/options and are not implied
by a server run.

Run evidence, every measured baseline, gate output and profiles live in
[issue #642](https://git.kayg.org/kayg/calternal/issues/642), never in committed
measurement artifacts. Preserve the historical all-SSD table above for comparison.

Live scenario samples and destructive Trash samples use disjoint ranges based on
`--runs`. Fixtures provide up to 600 samples, preserving the original file bytes;
old sample manifests are regenerated when too small. An insufficient fixture fails
before any timed run instead of deleting a later run's note.

ADR 0003 evidence migration: `docs/perf/budgets.md` Source commit: [a4574fea2b107efd11858603c12d6cdab49a5e76](https://git.kayg.org/kayg/calternal/commit/a4574fea2b107efd11858603c12d6cdab49a5e76); snapshot from dev `55f35fcd`. Full original source preserved below before repository removal/stripping. Design, code and test inputs are retained where applicable. ```text # Perf budgets Every PR is measured on the perf machine, and a broken budget blocks the merge ([ADR 0005](<../adr/0005-performance-is-a-merge-gate.md>)). This page says what is measured, how, and the limit for each number. The limits the harness checks live in [perf/budgets.json](<../../perf/budgets.json>); keep the two in step. ## How it is measured - **Machine**: the perf VM (4 vCPUs, 8 GB RAM, HDD Homes and SSD app state, Debian), quiet, used by nothing else while it runs. Its disks have no host cache, and the page cache is emptied before every server start (`--drop-caches`), so every start reads from disk like a fresh boot. The official layout uses existing ext4 `/mnt/b/hdd-ext4` (rotational sdb1) for Homes, matching production ext4, and `/mnt/z4-nvme` (non-rotational sde) for state. Reports identify both filesystems. - **Homes**: made by `calternal-fixtures`, the same bytes for the same seed: 1,000, 10,000 and 100,000 notes. About 30% daily notes with log entries, the rest regular notes (mostly short, some long, one in 2,000 with 50,000 words), with links, tags, tasks and attachment references. - **Runs**: `calternal-perf` starts the real `calternal` binary. First on fresh copies of the Home that were never indexed (`cold.*`, 3 runs), then 5 times on the indexed Home, each time a fresh server process. - **Numbers**: each run gives a p50 and p95 per metric. The report shows the median of those over the runs, plus **noise**: how far the runs' p50s spread, as a percent of their median. A metric measured once per run (startup) pools the runs: p50 is the median run, p95 the slowest. **Max** is the largest observed sample across all runs. Budgets are on p95 unless they say otherwise. - **Noise band**: a breach with noise over 25% is rerun before it counts (by hand for now; automatic once the gate is wired into PRs). Run it: `perf/run-vm.sh --sizes 1k,10k,100k --runs 5 --cold-runs 3` (about 40 minutes). Locally: `cargo build --release -p calternal -p calternal-perf`, then `target/release/calternal-perf --bin target/release/calternal --work /tmp/perf --budgets perf/budgets.json` (`--quick` for a smoke test). `--trash-only` runs just the delete, restore and permanent-delete scenario. The disk side on its own: `storage-bench` (in `crates/perf`) times history commits and note saves straight against the real code on whatever disk it is pointed at, with readers or a big upload going at the same time (#298). For example `storage-bench history --dir /mnt/z4-nvme/b` or `storage-bench save --dir /mnt/z4-nvme/b --upload plain`. ## Budgets Times are milliseconds unless a unit is given. "All" means every Home size; a size column overrides it. | metric | budget (all sizes) | at 100k notes | target | gate | |---|---|---|---|---| | `startup.healthz` | p95 ≤ 300 | | p95 ≤ 100 | gated | | `cold.startup` | p95 ≤ 500 | | p95 ≤ 300 | gated | | `cold.index` (s) | 1k ≤ 5, 10k ≤ 10 | p95 ≤ 60 | | gated | | `cold.notes_per_s` | | | p50 ≥ 2000 notes/s | target | | `home.first_page` | p95 ≤ 300 | p95 ≤ 100 | | gated | | `home.page`, `home.page_title`, `home.page_tag`, `home.page_next` | p95 ≤ 50 | | | gated | | `search.query` | p95 ≤ 100 | | | gated | | `search.first_query` | p95 ≤ 1000 | | | target | | `journal.catch_up` | p95 ≤ 1000 | p95 ≤ 2000 | | gated | | `open.note` | p95 ≤ 15 | | | gated | | `open.api_get` | p95 ≤ 50 | | | gated | | `open.long_note` (50k words) | p95 ≤ 250 | | | gated | | `sync.round_trip` | p95 ≤ 10 | | | gated | | `sync.save_ack` | p95 ≤ 40 | | | gated | | `storm.save_ack` | p95 ≤ 150 | | p95 ≤ 50 | gated | | `storm.dropped_clients` | 0 | | | gated | | `storm.converge` | p95 ≤ 2000 | | | gated | | storm: lost or doubled text | never | | | gated (a failure, not a number) | | `storm.edits_per_s` | | | p50 ≥ 1000 edits/s | target | | `storm.disk_written` (10k keystrokes) | | | p95 ≤ 50 MB | target | | `mem.idle` | p95 ≤ 64 MB | | | gated | | `mem.peak` | p95 ≤ 256 MB | p95 ≤ 256 MB | | gated (100k: target) | | `mem.after_opens` | | p95 ≤ 300 MB | | target | | `shutdown` | p95 ≤ 1000 | | | gated | | `idle.cpu_pct` | ≤ 0.1 % | | 0 | gated | | `idle.wakeups_per_s` | ≤ 0.2 /s | | 0 | gated | | `idle.rss` | | ≤ 100 MB | | gated | | `load.typing_cpu_pct` | ≤ 2 % | | | gated | | `soak.idle_ratchet` (MB), `soak.idle_slope` (MB/h) (with `--soak-secs`) | ≤ 5, ≤ 20 | | 0 | target | The gated limits sit above today's baseline with room for the noise we see (a no-cache disk makes every fsync slow and jumpy); the targets are where we want to be. Tighten a gated limit whenever a change makes the number better, so the gain can't quietly be lost again. **Gated** budgets block a merge today. **Target** budgets are what we want, but the code doesn't meet them yet; they are reported and become gates when the work that meets them lands (see "Known problems"). ## What each metric means - `startup.healthz`: process start until `/healthz` answers. Startup never waits (ADR 0016), so this must not grow with the Home. - `home.first_page`: the first request after start, a page of 50 notes; it waits for the Home to open (id index, list store, history). - `home.page`, `home.page_title`, `home.page_tag`: a page of 50, newest change first, A to Z, and filtered by `#work`. `home.page_next`: 20 pages on through a cursor. `home.page_big`: five pages of 2,000 on through a cursor, the app's background fill (#422). - `journal.catch_up`: a client that was away reads the whole change journal from the start, 1,000 entries a page (`journal.entries` says how many). - `open.note`: joining a note's live room until the whole note arrived (what opening a note in the editor waits for), first open in this process. - `open.api_get`: `notes.get` of a note not open yet. - `open.long_note`: opening the 50,000-word note. - `sync.round_trip`: one keystroke from client A until client B has it. - `sync.save_ack`: one keystroke until the server answers its save check, which is what the editor's "Saved" waits for (history is durable). - `storm.*`: 4 clients type 10,000 keystrokes into one note, each with a save check, up to 8 unanswered per client; an outside app rewrites the file every 500 ms. Afterwards every copy and the server must agree, every outside line must be there exactly once, and the file must equal the note. `save_ack` is per keystroke under that load, `edits_per_s` the throughput, `converge` the time from the last answer until everyone agrees, `disk_written` the bytes the server wrote, `dropped_clients` clients the server cut off for falling behind. - `cold.*`: first start on a Home never indexed: `index` is the time until every note is in the id index, `notes_per_s` its rate. - `mem.idle` / `mem.after_first_page` / `mem.after_opens`: resident memory; `mem.peak` the most at any point in a run. - `shutdown`: SIGTERM until the process exited (it saves open notes first). - `idle.*` (first run of each size): once the Home has settled and every room has closed, CPU time (`/proc/<pid>/stat`), thread wake-ups (context switches of every thread, `/proc/<pid>/task/*/status`) and resident memory over `--idle-secs` (300 by default). An idle server must sleep: no polling, no tick timers. - `soak.*` (first run of each size, only with `--soak-secs N`; `--soak-secs 1800` is the 30-minute leak soak of #398): two cycles, each a third of the time of steady use (pages, a search, two notes opened in the editor and two through the API, ten keystrokes typed and taken out again with a save check, a page of the journal, round after round) and a sixth idle. Memory is sampled every 10 s into `soak-<notes>.tsv` in the work folder. A leak ratchets the idle level up: `idle_ratchet` is the second idle level minus the first (MB). `load_slope` is how fast memory grew under the first load once warm and `idle_slope` how it moved in the second idle stretch after the rooms closed, both in MB per hour. Under load a few hundred sample notes stay open and grow with every keystroke, so the load slope is real use, not a leak by itself; `idle_rss_1` / `idle_rss_2` / `load_rss_max` / `peak` give the levels, `rounds` how much was done. - `load.typing_*` (first run of each size): one person types five characters a second for a minute, with a save check every five, while a second client watches the same note: the server's CPU share and wake-ups. - `trash.delete`, `trash.restore`, `trash.forget` (10k notes and up): 30 interleaved API response timings per operation in every warm run. The forget notes are first put in the Trash outside the timed section; each delete is followed by restoring the same note. `trash.forget` measures permanent deletion from the Trash, including its history purge. ## Still to measure - The web client (boot, keystroke to paint, switching notes, scrolling, bundle size) has its own harness and `web.*` budgets in the same file: [web.md](<web.md>). - Backlinks. Full-text search is measured by `search.query` and `search.first_query` (ADR 0031). - Typing latency while a bulk edit runs for the same and another user (ADR 0014). ## Historical all-SSD baseline 2026-10-14, `dev` at e2f4928 plus this harness, on the perf VM (Linux 6.12, 4 vCPUs, 7.7 GB, ext4 on a non-rotational disk without host cache, page cache dropped before every start). 5 warm runs and 3 cold runs per size. | metric | unit | 1k p50 / p95 | 10k p50 / p95 | 100k p50 / p95 | worst noise | |---|---|---:|---:|---:|---:| | `startup.healthz` | ms | 40.7 / 52.0 | 32.8 / 35.7 | 27.3 / 29.0 | 55% | | `cold.startup` | ms | 118 / 123 | 85.0 / 85.3 | 70.8 / 86.2 | 42% | | `cold.first_list` | ms | 160 / 169 | 205 / 207 | 760 / 827 | 30% | | `cold.index` | s | 0.69 / 0.79 | 2.70 / 3.23 | 28.2 / 30.6 | 32% | | `cold.notes_per_s` | notes/s | 1449 / 1613 | 3702 / 4252 | 3549 / 3584 | 31% | | `cold.disk_written` | MB | 2.74 / 2.74 | 41.2 / 41.2 | 437 / 438 | 2% | | `cold.mem_peak` | MB | 29.6 / 30.4 | 107 / 111 | 807 / 821 | 7% | | `home.first_page` | ms | 40.6 / 90.0 | 129 / 185 | 1121 / 1367 | 164% | | `home.page` | ms | 1.66 / 2.79 | 1.08 / 1.77 | 3.01 / 4.41 | 127% | | `home.page_title` | ms | 1.46 / 1.59 | 1.05 / 1.24 | 2.74 / 3.35 | 142% | | `home.page_tag` | ms | 2.41 / 2.77 | 5.91 / 7.44 | 2.98 / 4.59 | 60% | | `home.page_next` | ms | 1.83 / 2.61 | 1.26 / 1.58 | 3.16 / 3.74 | 43% | | `home.first_list` | ms | 7.60 / 10.1 | 43.5 / 74.3 | 420 / 559 | 79% | | `home.list` | ms | 6.22 / 14.3 | 40.6 / 59.3 | 428 / 574 | 62% | | `journal.catch_up` | ms | 10.3 / 12.8 | 47.3 / 66.4 | 451 / 539 | 65% | | `journal.entries` | count | 1071 / 1142 | 10062 / 10122 | 100051 / 100097 | 13% | | `open.note` | ms | 51.0 / 80.5 | 51.0 / 55.2 | 50.9 / 51.9 | 12% | | `open.api_get` | ms | 10.0 / 13.9 | 9.53 / 16.5 | 7.78 / 9.09 | 57% | | `open.long_note` | ms | 13.6 / 21.2 | 20.2 / 31.1 | 27.3 / 35.6 | 90% | | `sync.round_trip` | ms | 0.67 / 1.53 | 0.50 / 0.64 | 0.49 / 0.65 | 35% | | `sync.save_ack` | ms | 9.06 / 16.4 | 8.53 / 11.3 | 5.93 / 7.39 | 24% | | `storm.save_ack` | ms | 47.0 / 72.7 | 43.4 / 62.7 | 42.3 / 48.6 | 36% | | `storm.edits_per_s` | edits/s | 637 / 728 | 734 / 744 | 888 / 1057 | 26% | | `storm.typing` | s | 15.7 / 17.7 | 13.6 / 16.0 | 11.3 / 11.8 | 25% | | `storm.converge` | ms | 176 / 179 | 172 / 452 | 164 / 175 | 166% | | `storm.disk_written` | MB | 57.6 / 65.2 | 55.4 / 61.0 | 57.5 / 121 | 127% | | `storm.outside_edits` | count | 32.0 / 35.0 | 28.0 / 32.0 | 23.0 / 24.0 | 22% | | `storm.dropped_clients` | count | 0.00 / 0.00 | 0.00 / 0.00 | 0.00 / 0.00 | 0% | | `mem.idle` | MB | 11.8 / 11.9 | 12.0 / 12.2 | 11.9 / 11.9 | 3% | | `mem.after_list` | MB | 15.9 / 17.3 | 27.7 / 28.4 | 180 / 186 | 25% | | `mem.after_opens` | MB | 26.9 / 27.5 | 78.9 / 86.4 | 728 / 873 | 42% | | `mem.peak` | MB | 31.6 / 35.5 | 83.1 / 92.8 | 771 / 941 | 35% | | `shutdown` | ms | 48.5 / 57.8 | 48.0 / 48.7 | 67.4 / 88.3 | 63% | Single-value metrics (startup, first page, long note) have one sample per run, so their noise is high; the latency distributions (200 to 10,000 samples per run) are steadier. An earlier run on `dev` at 5e727fd (before #78 and #83) showed what the harness is for: first-start indexing ran at 80 notes a second (18 minutes for 100k), every start journaled a fake outside change for every note never opened, a note took 80 keystrokes a second at 20 KB of disk writes each, and a keystroke reached the other device only after an fsync (10 ms). All four are fixed on `dev` now (35x, gone, 10x and 20x). ## Known problems the baseline shows 1. **Memory at 100k notes: 730 to 870 MB after opening a few dozen notes, peaks near 940 MB** (80 MB at 10k). It jumps after the startup scan settles, between listing (180 MB) and opening notes. The backlink map, rebuilt from every file on every start and keeping each link's line, is the likely cause; cold indexing peaks at 820 MB as well. 2. **The first request at 100k waits 1.1 to 1.4 s** for the Home to open (id index and list store), though every Home opens in the background at start; the page itself takes 3 ms. 130 ms at 10k. 3. **Opening a note for the first time takes a flat 51 ms at every Home size**, with almost no noise. It doesn't grow with the Home or the note, so it is a fixed cost (most likely several fsyncs in a row while the note is first written to history, about 9 ms each on this disk), worth finding. 4. **One note takes 640 to 890 keystrokes a second** (target 1,000) and the storm writes 55 to 60 MB for 10,000 keystrokes, about 5.6 KB each (target 50 MB). 5. The old whole-Home `notes.list` (deprecated) takes 0.4 to 0.6 s at 100k; the app uses pages, which take 3 to 7 ms at any size. (Removed in #398; `notes.list` without input now returns the first page.) The storm never lost or doubled text in any run, with 25 to 35 outside rewrites per run, and no client was ever dropped. ## Split storage measurement `perf/run-vm.sh` runs the full server gate with `--sizes 1k,10k,100k --runs 5 --cold-runs 3 --drop-caches --gate`. It holds `flock -o /root/perf-vm.lock`, waits for other server/perf processes and uses unique issue-owned roots. Run `PERF_LAYOUT=ssd PERF_NAME=ssd perf/run-vm.sh` for the same all-SSD comparison. Harness `--data-dir` controls fixtures and Home copies; `--state-dir` controls corresponding app stores. `--work` holds other harness output. Cold runs reset both roots; the first indexed pair is retained together for warm runs. `sync.save_ack` measures SSD history acknowledgement; `sync.durable_write` measures an edit through history and explicit `notes.save` completion (HDD atomic file and directory fsync, excluding the quiet timer). The latter is a separate 30-sample series after uninterrupted typing samples. `uploads.response` measures completion of a unique 8 MiB upload; `uploads.round_trip` and `uploads.save_ack` measure 200 keystrokes while those uploads run. These new observations have no blocking limit until measured; existing budgets are unchanged. Web/browser gates use `perf/web.sh --data-dir HDD --state-dir SSD --gate` and the same all-SSD comparison; they and optional soak targets have their own runners/options and are not implied by a server run. Run evidence, every measured baseline, gate output and profiles live in [issue #642](https://git.kayg.org/kayg/calternal/issues/642), never in committed measurement artifacts. Preserve the historical all-SSD table above for comparison. Live scenario samples and destructive Trash samples use disjoint ranges based on `--runs`. Fixtures provide up to 600 samples, preserving the original file bytes; old sample manifests are regenerated when too small. An insufficient fixture fails before any timed run instead of deleting a later run's note. ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#44
No description provided.