Notes: fast Home open at any size, nothing 'not found' mid-scan (#52) #54

Closed
kayg wants to merge 1 commit from issue/52-home-open into dev
Owner

Closes #52.

What changed

  • Index writes are batched. Everything queued goes out in one write and one fsync. A cold open used to open and fsync ids.jsonl once per note.
  • Warm opens validate by stat. After each scan, the size and modification time of every note file are saved in notes/scan-state.tsv. On the next open, files are only stated and only the changed ones are read. A first scan, with no saved state, takes already-indexed files as they are, so upgrading doesn't announce every note as changed.
  • Cold opens identify in batches. Unknown files have their heads read in parallel and are indexed in one batch. Journal events go out a thousand at a time.
  • Nothing is "not found" mid-scan.
    • notes.list returns incomplete: true until the startup scan finishes.
    • get, room join and explicit-id create look up a note the index doesn't know yet: a day by its file name, anything else by waiting for the scan (60 s cap).
    • So they never answer "not found" and never create a second note for the same day.
  • Homes open eagerly. Every Home starts opening in the background when the server starts, and /healthz never waits for it.
  • Fixed on the way: paths reported in the same moment as a rescan were dropped, so an outside edit landing in that window was missed. They're always checked now.

New code is in separate files (scan.rs, tests/opening.rs), with small edits to lib.rs, home.rs, index.rs, watch.rs, actions.rs and main.rs. The search agent's summary should return the same incomplete flag (Notes::incomplete(user)).

Numbers

Measured on calternal-dev's SSD. The perf VM was busy with the storage benchmark (load 32), so these aren't perf-VM numbers. Homes come from the #44 fixture generator, seed 1. Old is dev at d95b8e8, new is this branch. Cold means the index was removed and the page cache dropped.

notes cold, old: index complete cold, new: index complete cold: late note asked right after start warm, new: healthz / first list / scan done
1,000 10.0 s 0.26 s old not_found, new found (142 ms) 16 ms / 11 ms (all 1,000) / 0.10 s
10,000 119.6 s 0.76 s old not_found, new found (530 ms) 11 ms / 112 ms (all 10,000) / 0.35 s
100,000 ~20 min (extrapolated) 6.8 s new found (5.1 s, waits for the scan) 7 ms / 0.70 s (all 100,000) / 1.9-3.1 s

Warm 100k background work:

  • Old: re-reads and re-hashes every file after opening, 141 MB read in the first 8 s and still going, out of 422 MB of notes. It also announces every migrated note as changed.
  • New: 12.6 MB read in total (the id index plus the scan state).

Still open: the 100k list itself costs about 0.3 s to serialize per call. notes.list needs paging, which is outside #52.

Tests

  • 4 new tests:
    • a cold open indexes every file once with its own id (one index line per note)
    • asking mid-scan for a 4,000-note Home never answers "not found" and never duplicates a day
    • a warm open announces exactly the edit, the delete and the add made while closed
    • an upgrade with no saved scan announces nothing
  • The notes suite passes 3 times in a row (56 tests), and the workspace passes 182 tests. Clippy -D warnings is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Closes #52. ## What changed - **Index writes are batched.** Everything queued goes out in one write and one fsync. A cold open used to open and fsync `ids.jsonl` once per note. - **Warm opens validate by stat.** After each scan, the size and modification time of every note file are saved in `notes/scan-state.tsv`. On the next open, files are only `stat`ed and only the changed ones are read. A first scan, with no saved state, takes already-indexed files as they are, so upgrading doesn't announce every note as changed. - **Cold opens identify in batches.** Unknown files have their heads read in parallel and are indexed in one batch. Journal events go out a thousand at a time. - **Nothing is "not found" mid-scan.** - `notes.list` returns `incomplete: true` until the startup scan finishes. - `get`, room join and explicit-id `create` look up a note the index doesn't know yet: a day by its file name, anything else by waiting for the scan (60 s cap). - So they never answer "not found" and never create a second note for the same day. - **Homes open eagerly.** Every Home starts opening in the background when the server starts, and `/healthz` never waits for it. - **Fixed on the way:** paths reported in the same moment as a rescan were dropped, so an outside edit landing in that window was missed. They're always checked now. New code is in separate files (`scan.rs`, `tests/opening.rs`), with small edits to `lib.rs`, `home.rs`, `index.rs`, `watch.rs`, `actions.rs` and `main.rs`. The search agent's `summary` should return the same `incomplete` flag (`Notes::incomplete(user)`). ## Numbers Measured on calternal-dev's SSD. The perf VM was busy with the storage benchmark (load 32), so these aren't perf-VM numbers. Homes come from the #44 fixture generator, seed 1. Old is `dev` at d95b8e8, new is this branch. Cold means the index was removed and the page cache dropped. | notes | cold, old: index complete | cold, new: index complete | cold: late note asked right after start | warm, new: healthz / first list / scan done | |---|---|---|---|---| | 1,000 | 10.0 s | **0.26 s** | old `not_found`, new found (142 ms) | 16 ms / 11 ms (all 1,000) / 0.10 s | | 10,000 | 119.6 s | **0.76 s** | old `not_found`, new found (530 ms) | 11 ms / 112 ms (all 10,000) / 0.35 s | | 100,000 | ~20 min (extrapolated) | **6.8 s** | new found (5.1 s, waits for the scan) | 7 ms / 0.70 s (all 100,000) / 1.9-3.1 s | **Warm 100k background work:** - **Old:** re-reads and re-hashes every file after opening, 141 MB read in the first 8 s and still going, out of 422 MB of notes. It also announces every migrated note as changed. - **New:** 12.6 MB read in total (the id index plus the scan state). **Still open:** the 100k list itself costs about 0.3 s to serialize per call. `notes.list` needs paging, which is outside #52. ## Tests - 4 new tests: - a cold open indexes every file once with its own id (one index line per note) - asking mid-scan for a 4,000-note Home never answers "not found" and never duplicates a day - a warm open announces exactly the edit, the delete and the add made while closed - an upgrade with no saved scan announces nothing - The notes suite passes 3 times in a row (56 tests), and the workspace passes 182 tests. Clippy `-D warnings` is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Notes: open a Home fast at any size, never "not found" mid-scan (#52)
Some checks failed
CI / rust (pull_request) Failing after 31s
CI / web (pull_request) Successful in 57s
bdbccd3ce0
- The id index flushes everything queued in one write and one fsync
  (cold opens did one open+fsync per note).
- A warm open stats every file and compares it with the size and mtime
  saved after the last scan (notes/scan-state.tsv); only changed files
  are read. A first scan (no saved state) takes indexed files as they
  are, so upgrades don't announce every note as changed.
- A cold open reads unknown files' heads in parallel, indexes them in one
  batch and records journal events a thousand at a time.
- While the startup scan runs, notes.list says `incomplete: true`; get,
  room join and explicit-id create find a not-yet-indexed note first (a
  day by its file name, anything else by waiting for the scan), so they
  never answer "not found" and never make a second day.
- Every Home opens in the background at start; /healthz never waits.
- Fix found on the way: paths reported in the same moment as a rescan
  were dropped; they are always checked now.

Part of #52

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Superseded by the PR from issue/52-home-open-2 (adds the crash-before-first-save fix that CI's kill -9 test caught here).

Superseded by the PR from issue/52-home-open-2 (adds the crash-before-first-save fix that CI's kill -9 test caught here).
kayg closed this pull request 2026-10-13 19:28:02 +00:00
Some checks failed
CI / rust (pull_request) Failing after 31s
CI / web (pull_request) Successful in 57s

Pull request closed

Sign in to join this conversation.
No reviewers
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!54
No description provided.