Memory: allocator A/B (mimalloc), tunables, drop whole-Home list, lower the floor #398

Open
opened 2026-10-15 03:46:59 +00:00 by kayg · 3 comments
Owner

kayg, 2026-10-15, answering the #44 questions on #174:

  • Q5: "let's do it then": remove the deprecated whole-Home notes.list (the no-input form). The app only uses the paged form.
  • Q4: "let's benchmark and research the mimalloc allocator and set the 2 heap limit in the tunables. let's get memory usage further down!" Approved as long as nothing leaks.

Plan:

  1. Remove the whole-Home notes.list: the action, its tree builder (crates/notes/src/actions.rs "Every note at once") and the perf harness calls. Measured before: peak 269 → ~111 MB at 100k.
  2. Two heaps without code: GLIBC_TUNABLES=glibc.malloc.arena_max=2 in the deploy config (quadlet / systemd env for next, staging and cloud), instead of mallopt in #386.
  3. Allocator research and A/B at 100k on the perf VM:
    • glibc + tunables + malloc_trim (#314) + no-THP (#358);
    • mimalloc (v2 and v3; settings such as purge_delay and arena_eager_commit);
    • optionally jemalloc (background_thread, dirty_decay_ms).
      Measure idle RSS, peak RSS, every latency metric, and idle CPU/wake-ups (mimalloc's purge must not wake an idle server). Cite sources.
  4. Leak soak: 30 min at 100k, idle and under steady load, sampling RSS. It must stay flat. Make it a harness scenario.
  5. Push the idle floor down: SQLite cache_size/mmap per connection and the number of connections, search index caches, tokio worker count, buffers. Find where the ~30–40 MB of live heap and the rest of RSS goes.
  6. Cold-open peak (~300 MB, first open of a 100k Home): find and fix it.

Targets at 100k: idle < 50 MB, peak < 120 MB, cold-open peak < 150 MB, no latency regressions, idle CPU 0.

kayg, 2026-10-15, answering the #44 questions on #174: - **Q5:** "let's do it then": remove the deprecated whole-Home `notes.list` (the no-input form). The app only uses the paged form. - **Q4:** "let's benchmark and research the mimalloc allocator and set the 2 heap limit in the tunables. let's get memory usage further down!" Approved as long as nothing leaks. Plan: 1. **Remove the whole-Home `notes.list`:** the action, its tree builder (`crates/notes/src/actions.rs` "Every note at once") and the perf harness calls. Measured before: peak 269 → ~111 MB at 100k. 2. **Two heaps without code:** `GLIBC_TUNABLES=glibc.malloc.arena_max=2` in the deploy config (quadlet / systemd env for next, staging and cloud), instead of `mallopt` in #386. 3. **Allocator research and A/B at 100k on the perf VM:** - glibc + tunables + `malloc_trim` (#314) + no-THP (#358); - mimalloc (v2 and v3; settings such as `purge_delay` and `arena_eager_commit`); - optionally jemalloc (`background_thread`, `dirty_decay_ms`). Measure idle RSS, peak RSS, every latency metric, and idle CPU/wake-ups (mimalloc's purge must not wake an idle server). Cite sources. 4. **Leak soak:** 30 min at 100k, idle and under steady load, sampling RSS. It must stay flat. Make it a harness scenario. 5. **Push the idle floor down:** SQLite `cache_size`/mmap per connection and the number of connections, search index caches, tokio worker count, buffers. Find where the ~30–40 MB of live heap and the rest of RSS goes. 6. **Cold-open peak** (~300 MB, first open of a 100k Home): find and fix it. Targets at 100k: idle < 50 MB, peak < 120 MB, cold-open peak < 150 MB, no latency regressions, idle CPU 0.
Author
Owner

#398: allocator A/B, tunables, whole-Home list gone, floor and cold peak

All on the perf VM at 100k notes. Caches were dropped before every start, the VM lock was taken per run, and configurations were interleaved. The memory profiles come from staging (heaptrack). Values are the median over runs of each run's p50 / p95; run counts are in brackets.

Where it stands

metric target dev (3) all #398 PRs (3)
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 ✅
sync.save_ack ms p95 < 15 7.13 / 13.1 8.08 / 22.0 ⚠️
cold.index s 19.3 24.5 ⚠️
idle CPU, wake-ups/s 0 0, 0 0, 0 ✅

The two ⚠️ rows are noisy on this VM:

  • sync.save_ack p95 ranges 11.7 to 61.6 ms on dev itself (one per run) and 7.6 to 32.7 ms with the #398 PRs.
  • cold.index ranges 19.2 to 27.5 s on dev and 24.2 to 25.6 s with the PRs. It may be about 3 s slower; worth another look.

PRs, in merge order

  1. #417: removes the whole-Home notes.list. Without input, notes.list now returns the first page.
  2. #418: GLIBC_TUNABLES=glibc.malloc.arena_max=2 in both quadlets, checked with quadlet -dryrun and ld.so --list-tunables on staging. The perf harness passes the same setting. Replaces #386 (closed).
  3. #427: glibc stays, with malloc_trim after bursts and no transparent huge pages. Supersedes #314 and #358 (closed). The full allocator table and sources are there.
  4. #428: a compact id index, and SQLite caches let go after walks over a whole table. Idle drops from 66.8 to 39.8 MB.
  5. #429: an 8 MiB cache for the cold fill instead of 64 MiB. The cold peak drops from 297 to 196 MB.
  6. #435: the leak soak scenario (--soak-secs).

PRs 3 to 6 each sit on #417 alone and don't depend on each other. The order above is the one the numbers were taken in.

Allocator: glibc stays

idle MB peak p50 / p95 MB cold peak MB
glibc defaults (1) 183 142 / 180 546
glibc, 2 heaps (1) 130 108 / 131 310
glibc, 2 heaps + trim + no THP (4) 66.8 110 / 121 299
mimalloc v3, malloc replaced (1) 190 179 / 670 772
mimalloc v3, malloc replaced, no THP, purge_delay 0 (3) 72.0 108 / 291 354
mimalloc v2, malloc replaced (1) 125 178 / 489 870
jemalloc, malloc replaced (1) 193 216 / 224 646
jemalloc, narenas 2, decay 1 s, thp never (3) 74.2 118 / 131 342

Why glibc wins here:

  • A cold open runs about 75 threads: 64 file readers and 64 side-by-side search reads. Per-thread heaps keep what each thread freed.
  • Huge pages (always, Debian's default) roughly double idle memory for every allocator.
  • No allocator was faster on any request beyond this VM's noise.
  • None of them wakes an idle server: 0 CPU and 0 wake-ups in every configuration.
    • mimalloc creates no thread and purges only inside allocator calls.
    • jemalloc's background_thread is off by default.

Sources and details are on #427.

Leak soak, 30 minutes, two cycles

dev + 2 heaps all #398 PRs
idle after cycle 1 / 2 MB 120.6 / 144.6 65.1 / 73.0
idle ratchet MB +24.1 +7.9
idle slope MB/h 0 0
  • Under load, memory climbs on both builds. About 400 notes stay open, and each grows with every keystroke until its room closes.
  • With #398, it comes back down when the rooms close. On dev it stays up.
  • Nothing moves while idle.
  • The +7.9 MB step isn't explained yet. The typed text also grows the search index and its typo vocabulary, so part of it may be data. A soak with reading only, no typing, would tell data growth from a leak; that's the next run.

What's still open

  • Cold-open peak: 196 MB against the 150 target. A heap profile at the 196 MB peak shows a 116 MB heap. Its largest parts:
    • 57 MB of parsed links held for a batch of notes before it is stored;
    • 11 MB for the id index;
    • 8.5 MB for the scan's file table;
    • about 75 threads of allocator slack on top.
    • Two things didn't help: 16 or 8 readers instead of 64 (10 to 20 MB on staging), and a 1,024-note batch.
    • Next step: make the links smaller while a batch is held, and cap the reads running at once across scan and search.
  • The soak's +7.9 MB ratchet, as above.
  • Housekeeping on the perf VM: / was full (0 bytes free) when I started. I deleted my own #44 leftovers and moved five old v0-era benchmark folders to /mnt/z4-hdd/root-archive-2026-10-15/ (24 GB). Nothing was deleted except mine.
    • #298 held the VM lock for several runs in a row this morning (m9.sh; m8.sh under one flock).
## #398: allocator A/B, tunables, whole-Home list gone, floor and cold peak All on the perf VM at 100k notes. Caches were dropped before every start, the VM lock was taken per run, and configurations were interleaved. The memory profiles come from staging (heaptrack). Values are the median over runs of each run's p50 / p95; run counts are in brackets. ### Where it stands | metric | target | dev (3) | **all #398 PRs (3)** | |---|---|---|---| | 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 ✅ | | sync.save_ack ms | p95 < 15 | 7.13 / 13.1 | 8.08 / 22.0 ⚠️ | | cold.index s | | 19.3 | 24.5 ⚠️ | | idle CPU, wake-ups/s | 0 | 0, 0 | 0, 0 ✅ | The two ⚠️ rows are noisy on this VM: - **`sync.save_ack` p95** ranges 11.7 to 61.6 ms on dev itself (one per run) and 7.6 to 32.7 ms with the #398 PRs. - **`cold.index`** ranges 19.2 to 27.5 s on dev and 24.2 to 25.6 s with the PRs. It may be about 3 s slower; worth another look. ### PRs, in merge order 1. **#417**: removes the whole-Home `notes.list`. Without input, `notes.list` now returns the first page. 2. **#418**: `GLIBC_TUNABLES=glibc.malloc.arena_max=2` in both quadlets, checked with `quadlet -dryrun` and `ld.so --list-tunables` on staging. The perf harness passes the same setting. Replaces #386 (closed). 3. **#427**: glibc stays, with `malloc_trim` after bursts and no transparent huge pages. Supersedes #314 and #358 (closed). The full allocator table and sources are there. 4. **#428**: a compact id index, and SQLite caches let go after walks over a whole table. Idle drops from 66.8 to 39.8 MB. 5. **#429**: an 8 MiB cache for the cold fill instead of 64 MiB. The cold peak drops from 297 to 196 MB. 6. **#435**: the leak soak scenario (`--soak-secs`). PRs 3 to 6 each sit on #417 alone and don't depend on each other. The order above is the one the numbers were taken in. ### Allocator: glibc stays | | idle MB | peak p50 / p95 MB | cold peak MB | |---|---|---|---| | glibc defaults (1) | 183 | 142 / 180 | 546 | | glibc, 2 heaps (1) | 130 | 108 / 131 | 310 | | **glibc, 2 heaps + trim + no THP (4)** | **66.8** | **110 / 121** | **299** | | mimalloc v3, malloc replaced (1) | 190 | 179 / 670 | 772 | | mimalloc v3, malloc replaced, no THP, purge_delay 0 (3) | 72.0 | 108 / 291 | 354 | | mimalloc v2, malloc replaced (1) | 125 | 178 / 489 | 870 | | jemalloc, malloc replaced (1) | 193 | 216 / 224 | 646 | | jemalloc, narenas 2, decay 1 s, thp never (3) | 74.2 | 118 / 131 | 342 | Why glibc wins here: - A cold open runs about 75 threads: 64 file readers and 64 side-by-side search reads. Per-thread heaps keep what each thread freed. - Huge pages (`always`, Debian's default) roughly double idle memory for every allocator. - No allocator was faster on any request beyond this VM's noise. - None of them wakes an idle server: 0 CPU and 0 wake-ups in every configuration. - mimalloc creates no thread and purges only inside allocator calls. - jemalloc's `background_thread` is off by default. Sources and details are on #427. ### Leak soak, 30 minutes, two cycles | | dev + 2 heaps | all #398 PRs | |---|---|---| | idle after cycle 1 / 2 MB | 120.6 / 144.6 | 65.1 / 73.0 | | idle ratchet MB | +24.1 | **+7.9** | | idle slope MB/h | 0 | 0 | - **Under load, memory climbs on both builds.** About 400 notes stay open, and each grows with every keystroke until its room closes. - **With #398, it comes back down when the rooms close.** On dev it stays up. - **Nothing moves while idle.** - **The +7.9 MB step isn't explained yet.** The typed text also grows the search index and its typo vocabulary, so part of it may be data. A soak with reading only, no typing, would tell data growth from a leak; that's the next run. ### What's still open - **Cold-open peak: 196 MB against the 150 target.** A heap profile at the 196 MB peak shows a 116 MB heap. Its largest parts: - 57 MB of parsed links held for a batch of notes before it is stored; - 11 MB for the id index; - 8.5 MB for the scan's file table; - about 75 threads of allocator slack on top. - Two things didn't help: 16 or 8 readers instead of 64 (10 to 20 MB on staging), and a 1,024-note batch. - Next step: make the links smaller while a batch is held, and cap the reads running at once across scan and search. - **The soak's +7.9 MB ratchet**, as above. - **Housekeeping on the perf VM:** `/` was full (0 bytes free) when I started. I deleted my own #44 leftovers and moved five old v0-era benchmark folders to `/mnt/z4-hdd/root-archive-2026-10-15/` (24 GB). Nothing was deleted except mine. - #298 held the VM lock for several runs in a row this morning (`m9.sh; m8.sh` under one flock).
kayg referenced this issue from a commit 2026-10-15 11:26:48 +00:00
Author
Owner

#398 follow-ups: cold peak, leak, latency re-check, the idle floor, HDD

Perf VM, 100k notes, dropped caches, VM lock per run. The memory breakdowns are from staging, where heaptrack and smaps are measured.

1. Cold-open peak: under 150 MB (#459)

#459 changes three things:

  • link lists sized to fit (57 MB of the heap peak was buffer reuse);
  • compact scan announcements (from #388);
  • one shared limit of 16 file reads across the scan, the note list and search.
cold.mem_peak MB cold.index s, SSD cold.index s, rotational disk
dev, 2 heaps 305–328 25.0 (5 runs) 41.8 (6 runs)
all #398 PRs before #459 185 25.3 52.8
with #459 123 (121–124) 18.0–26.6 44.8 (6 runs, +7%)
  • #429 alone costs about 30% on a rotational disk (55.2 s against 41.6 s). #459 wins it back, so they should merge together. I put the same note on #429.
  • A bigger cache only for making the indexes (32 or 64 MiB) didn't help on either disk, and it raises the peak to 175 and 230 MB.

2. Read-only soak: no leak

This is 30 minutes and about 53,000 rounds, with no typing (--soak-read-only, added to #435):

  • the idle ratchet is −1.1 MB (57.0 MB after cycle 1, then 55.9 MB);
  • the load slope is 0.6 MB/h.

The +7.9 MB step in the typing soak was data growth: notes, history and the search index.

3. cold.index and search p95: no slowdown from any PR

  • Interleaved harness runs, 5 each:

    dev, 2 heaps all #398 PRs
    cold.index s 25.0 23.2
    search p95 ms, each run 16.7–23.8 16.0–24.0
  • Per PR, 8 interleaved starts each. Each start has a first page and 110 searches once search has caught up. Medians:

    dev #417 #427 #428 #429 all
    first page ms 12.9 12.2 12.3 12.2 12.4 12.3
    search p95 ms 11.0 10.0 10.7 10.5 11.0 11.2

    The slow outliers (26 to 83 ms first pages) show up in every build, dev included.

  • The earlier 24.5 s against 19.3 s for cold.index was disk noise on this VM.

4. How low can idle go? (kayg: "under 5 MB maybe?")

Today's idle at 100k notes. On staging, all #398 PRs, warm Home, 90 s idle: RSS 31.2 MB = 14.9 MB file-backed + 16.3 MB anonymous. The perf VM's harness reads 39 to 42 MB, because it measures after opens, the edit storm and typing.

part MB kind
calternal binary, code pages touched 10.8 file, clean, reclaimable
shared libraries (libcrypto 2.0, libc 1.6, others) 4.9 file, shared
search -shm 0.2 file
id index (strings 5.5, slot list 3.2, two tables 1.3) 10.0 heap
SQLite page caches, every database together 0.7 heap
everything else live (registry, schemas, tokio, tracing) 0.6 heap
allocator slack + 10 thread stacks ~5 anonymous
  • The search index is SQLite FTS5 read through the page cache. Nothing in it is memory-mapped beyond the 0.2 MB -shm.
  • Live heap (heaptrack, server killed while idle): 11.3 MB, of which the id index is 89%.

Floor of an empty process (no Home opened): RSS 15.1 MB = 13.4 MB file-backed + 1.8 MB anonymous, 5 threads.

Prototype: idle Homes unload (#460). After 10 minutes with no lookup, no open note and no job, a Home drops its id index. The next lookup reads ids.jsonl back, which takes 45 ms now that plain ASCII names skip Unicode normalising. Nothing polls. Results:

perf VM, 100k SSD rotational disk
idle RSS unloaded MB 19–25 23–33
anonymous memory unloaded MB 5–11 9–19
first note open after unloading, page cache dropped, ms 125 / 169 / 265 145 / 221 / 243

5. What's achievable, honestly

  • 5 MB of RSS is not reachable with this binary. The process maps 13 to 15 MB of code and libraries (10.8 MB of our binary's pages, 4.9 MB of shared libraries). That memory is clean, shared and reclaimable by the kernel under pressure, but RSS counts it.
  • Getting RSS toward 10 MB would mean a smaller binary. For example opt-level = "s", LTO, and rustls instead of OpenSSL; I haven't measured these.
  • About 5 MB of anonymous memory is reachable. With #460 the anonymous part at 100k went to 5–11 MB on the perf VM. The empty-process floor is 1.8 MB. What remains above that is allocator slack and thread stacks, plus the list store and search caches.
  • Realistic idle at 100k: ~20 to 25 MB RSS, of which ~5 to 10 MB is the server's own.

6. HDD (sdb1, ext4, ROTA=1)

Today's numbers are on sda, which reports ROTA=0. On the rotational disk, one run of each with 3 warm runs inside (p50 / p95):

metric dev, 2 heaps all #398 PRs all + #459
cold.index s 41.8 (6 runs) 52.8 44.8 (6 runs)
search.query ms 4.37 / 17.8 3.93 / 14.6 p95 8–10
open.note ms 1.15 / 2.79 1.15 / 2.49 p95 2.4–3.2
first note after unloading (#460) ms 145–243
sync.save_ack ms (fsync-bound, #298's area) 18.9 / 47.2 15.6 / 47.1

PRs

## #398 follow-ups: cold peak, leak, latency re-check, the idle floor, HDD Perf VM, 100k notes, dropped caches, VM lock per run. The memory breakdowns are from staging, where heaptrack and smaps are measured. ### 1. Cold-open peak: under 150 MB (#459) #459 changes three things: - link lists sized to fit (57 MB of the heap peak was buffer reuse); - compact scan announcements (from #388); - one shared limit of 16 file reads across the scan, the note list and search. | | cold.mem_peak MB | cold.index s, SSD | cold.index s, rotational disk | |---|---|---|---| | dev, 2 heaps | 305–328 | 25.0 (5 runs) | 41.8 (6 runs) | | all #398 PRs before #459 | 185 | 25.3 | 52.8 | | **with #459** | **123** (121–124) | 18.0–26.6 | **44.8** (6 runs, +7%) | - **#429 alone costs about 30% on a rotational disk** (55.2 s against 41.6 s). #459 wins it back, so they should merge together. I put the same note on #429. - **A bigger cache only for making the indexes (32 or 64 MiB) didn't help** on either disk, and it raises the peak to 175 and 230 MB. ### 2. Read-only soak: no leak This is 30 minutes and about 53,000 rounds, with no typing (`--soak-read-only`, added to #435): - the idle ratchet is **−1.1 MB** (57.0 MB after cycle 1, then 55.9 MB); - the load slope is 0.6 MB/h. The +7.9 MB step in the typing soak was data growth: notes, history and the search index. ### 3. cold.index and search p95: no slowdown from any PR - **Interleaved harness runs, 5 each:** | | dev, 2 heaps | all #398 PRs | |---|---|---| | cold.index s | 25.0 | 23.2 | | search p95 ms, each run | 16.7–23.8 | 16.0–24.0 | - **Per PR, 8 interleaved starts each.** Each start has a first page and 110 searches once search has caught up. Medians: | | dev | #417 | #427 | #428 | #429 | all | |---|---|---|---|---|---|---| | first page ms | 12.9 | 12.2 | 12.3 | 12.2 | 12.4 | 12.3 | | search p95 ms | 11.0 | 10.0 | 10.7 | 10.5 | 11.0 | 11.2 | The slow outliers (26 to 83 ms first pages) show up in every build, dev included. - The earlier 24.5 s against 19.3 s for `cold.index` was disk noise on this VM. ### 4. How low can idle go? (kayg: "under 5 MB maybe?") **Today's idle at 100k notes.** On staging, all #398 PRs, warm Home, 90 s idle: **RSS 31.2 MB = 14.9 MB file-backed + 16.3 MB anonymous.** The perf VM's harness reads 39 to 42 MB, because it measures after opens, the edit storm and typing. | part | MB | kind | |---|---|---| | `calternal` binary, code pages touched | 10.8 | file, clean, reclaimable | | shared libraries (libcrypto 2.0, libc 1.6, others) | 4.9 | file, shared | | search `-shm` | 0.2 | file | | **id index** (strings 5.5, slot list 3.2, two tables 1.3) | **10.0** | heap | | SQLite page caches, every database together | 0.7 | heap | | everything else live (registry, schemas, tokio, tracing) | 0.6 | heap | | allocator slack + 10 thread stacks | ~5 | anonymous | - The search index is SQLite FTS5 read through the page cache. Nothing in it is memory-mapped beyond the 0.2 MB `-shm`. - Live heap (heaptrack, server killed while idle): **11.3 MB**, of which the id index is 89%. **Floor of an empty process** (no Home opened): **RSS 15.1 MB = 13.4 MB file-backed + 1.8 MB anonymous**, 5 threads. **Prototype: idle Homes unload (#460).** After 10 minutes with no lookup, no open note and no job, a Home drops its id index. The next lookup reads `ids.jsonl` back, which takes 45 ms now that plain ASCII names skip Unicode normalising. Nothing polls. Results: | perf VM, 100k | SSD | rotational disk | |---|---|---| | idle RSS unloaded MB | **19–25** | 23–33 | | anonymous memory unloaded MB | **5–11** | 9–19 | | first note open after unloading, page cache dropped, ms | 125 / 169 / 265 | 145 / 221 / 243 | ### 5. What's achievable, honestly - **5 MB of RSS is not reachable with this binary.** The process maps 13 to 15 MB of code and libraries (10.8 MB of our binary's pages, 4.9 MB of shared libraries). That memory is clean, shared and reclaimable by the kernel under pressure, but RSS counts it. - **Getting RSS toward 10 MB would mean a smaller binary.** For example `opt-level = "s"`, LTO, and rustls instead of OpenSSL; I haven't measured these. - **About 5 MB of anonymous memory is reachable.** With #460 the anonymous part at 100k went to 5–11 MB on the perf VM. The empty-process floor is 1.8 MB. What remains above that is allocator slack and thread stacks, plus the list store and search caches. - **Realistic idle at 100k: ~20 to 25 MB RSS, of which ~5 to 10 MB is the server's own.** ### 6. HDD (sdb1, ext4, ROTA=1) Today's numbers are on sda, which reports ROTA=0. On the rotational disk, one run of each with 3 warm runs inside (p50 / p95): | metric | dev, 2 heaps | all #398 PRs | all + #459 | |---|---|---|---| | cold.index s | 41.8 (6 runs) | 52.8 | 44.8 (6 runs) | | search.query ms | 4.37 / 17.8 | 3.93 / 14.6 | p95 8–10 | | open.note ms | 1.15 / 2.79 | 1.15 / 2.49 | p95 2.4–3.2 | | first note after unloading (#460) ms | | | 145–243 | | sync.save_ack ms (fsync-bound, #298's area) | 18.9 / 47.2 | 15.6 / 47.1 | | ### PRs - **New:** #459 (cold peak) and #460 (unload prototype). #435 gained `--soak-read-only`. - **Merge order:** #417, #418, #427, #428, then #429 together with #459, then #435. #460 after review.
Author
Owner

#398: rebased PRs, and how far a smaller binary goes

Rebased onto current dev (after train m, #444)

  • #462 replaces #459 (cold peak). Prod has #429 without it, so cold indexing on a rotational disk is about 30% slower there until #462 lands.
  • #463 replaces #460 (idle Homes unload), now production quality:
    • Config: Options::unload_after, 10 minutes by default; in the server, CALTERNAL_NOTES_UNLOAD_SECS (0 never unloads).
    • Never while a client is connected: a new EventRecorder::connected, which the engine answers from its live listeners.
    • Tests: an unused Home unloads and answers after; an open note keeps the index; a connected client keeps it; the engine's connected follows live views.
    • Docs: doc comments on the option, the trait method and the module.
  • #459 and #460 are closed. Both new PRs: cargo fmt, clippy -D warnings and the workspace tests are clean.

Smaller binary vs idle RSS

Perf VM, 100k notes.

  • Memory: 3 starts per build (warm Home, 90 s idle). File-backed memory is the clean comparison; anonymous memory varies by ±6 MB between starts with the same binary.
  • Latency: 2 interleaved harness runs for every build, and 4 to 5 for opt-level 3, + LTO and panic = "abort".
build binary MB its code resident MB file-backed MB anonymous MB (median) search p50 / p95 ms open p95 ms cold.index s
opt-level 3 (today) 24.8 11.0 14.7 22.3 5.3 / 19.2 2.9 22.5
+ fat LTO + codegen-units 1 17.6 9.4 13.2 20.5 4.3 / 17.2 3.5 23.4
+ strip symbols 18.6 11.0 14.7 23.6 (same code)
panic = "abort" 19.6 9.7 13.4 26.3 4.7 / 16.6 3.1 21.8
opt-level = "s" 22.7 8.9 12.5 20.1 5.0 / 21.0 2.5 30.9 (23–39)
"s" + fat LTO + strip 10.6 7.0 10.9 26.0 4.6 / 19.3 3.3 27.9 (24–32)

What I'd do with each:

  • Recommended: fat LTO + 1 codegen unit (#466).
    • 1.5 MB less mapped code.
    • As fast or faster: search p50 −1 ms, the edit storm 2,556 → 3,435 edits/s, save ack p95 8.0 → 5.8 ms. Open and cold.index are within noise.
    • Costs about 50% more release build time (103 → 157 s on staging).
  • Not opt-level = "s". It saves another 0.7 to 2.3 MB, but cold indexing is 40 to 60% slower.
  • Not panic = "abort". It saves 1.3 MB, but a panic in one request would take down the whole server instead of failing that one task, and the saves that run on drop would be skipped.
  • Strip doesn't move RSS. Symbols aren't mapped into memory; stripping only saves 6 MB on disk, and backtraces and release profiles lose function names.
  • rustls doesn't apply. Only webauthn-rs uses OpenSSL, for passkey signature checks, not TLS. Removing libcrypto (2 MB of the shared-library pages) means replacing the passkey library.

Bottom line: the build can take about 1.5 MB off file-backed RSS (14.7 → 13.2 MB) without costing speed. Together with #463, idle at 100k comes to about 18 to 23 MB RSS, of which 5 to 10 MB is the server's own memory.

## #398: rebased PRs, and how far a smaller binary goes ### Rebased onto current dev (after train m, #444) - **#462** replaces #459 (cold peak). Prod has #429 without it, so cold indexing on a rotational disk is about 30% slower there until #462 lands. - **#463** replaces #460 (idle Homes unload), now production quality: - **Config:** `Options::unload_after`, 10 minutes by default; in the server, `CALTERNAL_NOTES_UNLOAD_SECS` (`0` never unloads). - **Never while a client is connected:** a new `EventRecorder::connected`, which the engine answers from its live listeners. - **Tests:** an unused Home unloads and answers after; an open note keeps the index; a connected client keeps it; the engine's `connected` follows live views. - **Docs:** doc comments on the option, the trait method and the module. - #459 and #460 are closed. Both new PRs: `cargo fmt`, `clippy -D warnings` and the workspace tests are clean. ### Smaller binary vs idle RSS Perf VM, 100k notes. - **Memory:** 3 starts per build (warm Home, 90 s idle). File-backed memory is the clean comparison; anonymous memory varies by ±6 MB between starts with the same binary. - **Latency:** 2 interleaved harness runs for every build, and 4 to 5 for opt-level 3, + LTO and `panic = "abort"`. | build | binary MB | its code resident MB | file-backed MB | anonymous MB (median) | search p50 / p95 ms | open p95 ms | cold.index s | |---|---|---|---|---|---|---|---| | opt-level 3 (today) | 24.8 | 11.0 | 14.7 | 22.3 | 5.3 / 19.2 | 2.9 | 22.5 | | **+ fat LTO + codegen-units 1** | 17.6 | 9.4 | **13.2** | 20.5 | **4.3 / 17.2** | 3.5 | 23.4 | | + strip symbols | 18.6 | 11.0 | 14.7 | 23.6 | (same code) | | | | `panic = "abort"` | 19.6 | 9.7 | 13.4 | 26.3 | 4.7 / 16.6 | 3.1 | 21.8 | | `opt-level = "s"` | 22.7 | 8.9 | 12.5 | 20.1 | 5.0 / 21.0 | 2.5 | **30.9** (23–39) | | `"s"` + fat LTO + strip | 10.6 | 7.0 | 10.9 | 26.0 | 4.6 / 19.3 | 3.3 | **27.9** (24–32) | What I'd do with each: - **Recommended: fat LTO + 1 codegen unit (#466).** - 1.5 MB less mapped code. - As fast or faster: search p50 −1 ms, the edit storm 2,556 → 3,435 edits/s, save ack p95 8.0 → 5.8 ms. Open and cold.index are within noise. - Costs about 50% more release build time (103 → 157 s on staging). - **Not `opt-level = "s"`.** It saves another 0.7 to 2.3 MB, but cold indexing is 40 to 60% slower. - **Not `panic = "abort"`.** It saves 1.3 MB, but a panic in one request would take down the whole server instead of failing that one task, and the saves that run on drop would be skipped. - **Strip doesn't move RSS.** Symbols aren't mapped into memory; stripping only saves 6 MB on disk, and backtraces and release profiles lose function names. - **rustls doesn't apply.** Only `webauthn-rs` uses OpenSSL, for passkey signature checks, not TLS. Removing libcrypto (2 MB of the shared-library pages) means replacing the passkey library. **Bottom line:** the build can take about 1.5 MB off file-backed RSS (14.7 → 13.2 MB) without costing speed. Together with #463, idle at 100k comes to about 18 to 23 MB RSS, of which 5 to 10 MB is the server's own memory.
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#398
No description provided.