Arrowing through notes shows every note's full content instantly #150

Closed
opened 2026-10-14 05:57:42 +00:00 by kayg · 2 comments
Owner

kayg: "when I spam down or up arrow in the middle pane, in passing I just see the title loading on the right side / editor pane and not the contents? ... I want the full contents of the note appearing and disappearing (text, images, whatever....) - that's how fast I want our app to be."

Target: holding ↓ or ↑ in the list (key repeat about 30/s) paints each note's full content, text and images, in the same frame as the selection moves. No title-only frames, no blank editor, no layout jump.

Likely pieces:

  • Show each note's last-known text straight away, without a round trip:
    • Keep a small in-memory and IndexedDB cache of recent and nearby notes.
    • Prefetch the neighbours of the selection, plus the visible list page, in the background at idle priority. Keep it bounded.
    • Render the cached text at once, read-only and in the same editor, then attach the live room behind it without moving anything.
  • Reuse one editor view by swapping its state, instead of mounting a new editor per note.
  • Don't join a live room on every arrow step. Join only once the selection rests for a moment, about 150 ms.
  • Images: decode them ahead of time for the prefetched neighbours.
  • Measure:
    • frame time per arrow step on a 10k-note Home and a 2,000-line note;
    • a Playwright perf test that holds ↓ for 3 s and checks every frame shows the selected note's text;
    • the budget goes in perf budgets.
  • Zero idle cost: no prefetch while idle beyond the bounded set.
kayg: "when I spam down or up arrow in the middle pane, in passing I just see the title loading on the right side / editor pane and not the contents? ... I want the full contents of the note appearing and disappearing (text, images, whatever....) - that's how fast I want our app to be." **Target:** holding ↓ or ↑ in the list (key repeat about 30/s) paints each note's full content, text and images, in the same frame as the selection moves. No title-only frames, no blank editor, no layout jump. **Likely pieces:** - Show each note's last-known text straight away, without a round trip: - Keep a small in-memory and IndexedDB cache of recent and nearby notes. - Prefetch the neighbours of the selection, plus the visible list page, in the background at idle priority. Keep it bounded. - Render the cached text at once, read-only and in the same editor, then attach the live room behind it without moving anything. - Reuse one editor view by swapping its state, instead of mounting a new editor per note. - Don't join a live room on every arrow step. Join only once the selection rests for a moment, about 150 ms. - Images: decode them ahead of time for the prefetched neighbours. - Measure: - frame time per arrow step on a 10k-note Home and a 2,000-line note; - a Playwright perf test that holds ↓ for 3 s and checks every frame shows the selected note's text; - the budget goes in perf budgets. - Zero idle cost: no prefetch while idle beyond the bounded set.
Author
Owner

Profile: what one ↓ step does today (dev before this issue)

10k Home (n10000-s1 fixture), release server, production web build, headless Chromium 1440×900, Playwright with the page instrumented (WebSocket, IndexedDB, history, every frame) plus Chrome traces and CPU profiles. The build box was at load 60–120 on 12 cores the whole time, so absolute wall times are inflated; I ran the browser at nice -15 and also report main-thread CPU time from the trace (tdur), which contention doesn't inflate.

One ↓ step to a note this browser has never opened (ms after the key):

t (ms) what happens
0 key
0.9 route changes (history.pushState)
4.6 old editor unmounts, leaves its room
12 → 27 opens IndexedDB calternal-notes-meta again (a fresh open per note)
28 → 31 creates a new IndexedDB database calternal-note-<id>, reads it: 0 updates
47 new CodeMirror view mounted, empty → blank frames from here
47 → 56 room join → joined
56 → 57 step1 / step2 arrive, text inserted through Yjs → CodeMirror (whole note as one remote change)
66–480 first frame showing the note in full (median of 6 steps: ~350 ms; blank frames before it in 4 of 6)

Holding ↓ at 30/s for 3 s on the same Home: 0 % of frames showed the picked note (12 frames rendered, all blank), because every step tears down the editor before the room of the previous one ever answered.

Where the main thread goes per step (CPU profile): applying the server's state to an empty editor (Yjs → y-codemirror → full CodeMirror rebuild, ~45 % of JS), Svelte remounting the Editor, a forced layout from CodeMirror reading the DOM selection right after the swap, and per-step IndexedDB opens. Two unrelated long tasks also showed up: the sky's clouds repaint every minute (the effect read the clock directly), and every visible link scanned all 10,000 notes to resolve its target.

Fix (in the PR)

  1. One editor, previews first. The editor stays mounted. A picked note is drawn at once from its last-known text, read-only (NoteEditor.preview): preview → preview swaps the text in place (no new state, no re-measure). The live document is attached (NoteEditor.attach) once the selection rests 150 ms (keyboard) or straight away (mouse), and only after the room caught up, so text never steps back. A preview refuses every change (read-only + a transaction filter); clicking or typing into it attaches the live note first. The room's document is the only thing ever edited, rebuilt-from-document rules unchanged (ADR 0020).
  2. Remembered text (lib/peek.ts): memory (400 notes) + IndexedDB (2,000), marked stale by the journal, forgotten on sign-out. The list asks for 60 notes ahead in the direction of travel, 10 behind, and the rows on screen; nothing else, nothing while idle.
  3. notes.peek (new action): up to 50 notes' text in one request, from the open room or the file; never opens a room.
  4. An arrow walk writes the address once the steps stop (one history entry; Back returns to where the walk began).
  5. Small wins on every switch: notes-meta IndexedDB opened once per page; a file index for link lookups; clouds repaint only when the light changes.
  6. kayg's follow-up: opening with the mouse/tap is now a 140 ms ease-out opacity fade on the text only, no movement; the keyboard never animates.

Images aren't drawn by the editor yet (![](…) shows as text), so there is nothing to pre-decode; the prefetch is the hook for it when images arrive.

Numbers before/after follow once CI is green.

## Profile: what one ↓ step does today (dev before this issue) 10k Home (`n10000-s1` fixture), release server, production web build, headless Chromium 1440×900, Playwright with the page instrumented (WebSocket, IndexedDB, history, every frame) plus Chrome traces and CPU profiles. The build box was at load 60–120 on 12 cores the whole time, so absolute wall times are inflated; I ran the browser at `nice -15` and also report main-thread **CPU** time from the trace (`tdur`), which contention doesn't inflate. One ↓ step to a note this browser has never opened (ms after the key): | t (ms) | what happens | |---|---| | 0 | key | | 0.9 | route changes (`history.pushState`) | | 4.6 | old editor unmounts, leaves its room | | 12 → 27 | opens IndexedDB `calternal-notes-meta` again (a fresh open per note) | | 28 → 31 | **creates** a new IndexedDB database `calternal-note-<id>`, reads it: 0 updates | | 47 | new CodeMirror view mounted, **empty** → blank frames from here | | 47 → 56 | room join → `joined` | | 56 → 57 | step1 / step2 arrive, text inserted through Yjs → CodeMirror (whole note as one remote change) | | 66–480 | first frame showing the note in full (median of 6 steps: ~350 ms; blank frames before it in 4 of 6) | Holding ↓ at 30/s for 3 s on the same Home: **0 % of frames showed the picked note** (12 frames rendered, all blank), because every step tears down the editor before the room of the previous one ever answered. Where the main thread goes per step (CPU profile): applying the server's state to an empty editor (Yjs → y-codemirror → full CodeMirror rebuild, ~45 % of JS), Svelte remounting the Editor, a forced layout from CodeMirror reading the DOM selection right after the swap, and per-step IndexedDB opens. Two unrelated long tasks also showed up: the sky's clouds repaint every minute (the effect read the clock directly), and every visible link scanned all 10,000 notes to resolve its target. ## Fix (in the PR) 1. **One editor, previews first.** The editor stays mounted. A picked note is drawn at once from its last-known text, read-only (`NoteEditor.preview`): preview → preview swaps the text in place (no new state, no re-measure). The live document is attached (`NoteEditor.attach`) once the selection rests 150 ms (keyboard) or straight away (mouse), and only after the room caught up, so text never steps back. A preview refuses every change (read-only + a transaction filter); clicking or typing into it attaches the live note first. The room's document is the only thing ever edited, rebuilt-from-document rules unchanged (ADR 0020). 2. **Remembered text** (`lib/peek.ts`): memory (400 notes) + IndexedDB (2,000), marked stale by the journal, forgotten on sign-out. The list asks for 60 notes ahead in the direction of travel, 10 behind, and the rows on screen; nothing else, nothing while idle. 3. **`notes.peek`** (new action): up to 50 notes' text in one request, from the open room or the file; never opens a room. 4. An arrow walk writes the address once the steps stop (one history entry; Back returns to where the walk began). 5. Small wins on every switch: notes-meta IndexedDB opened once per page; a file index for link lookups; clouds repaint only when the light changes. 6. kayg's follow-up: opening with the mouse/tap is now a 140 ms ease-out opacity fade on the text only, no movement; the keyboard never animates. Images aren't drawn by the editor yet (`![](…)` shows as text), so there is nothing to pre-decode; the prefetch is the hook for it when images arrive. Numbers before/after follow once CI is green.
Author
Owner

Before / after (PR #243)

Setup: the 10k Home, a release server and a production build in headless Chromium at 1440. The build box sat at load 60–120 on 12 cores throughout, so the browser ran at nice -15. Wall-clock frame times here are mostly the software rasteriser fighting for CPU, which is why the main-thread CPU numbers (trace tdur) are the fair comparison. Before = dev at the start of this issue; after = this PR.

before after
One ↓ step: key → picked note shown in full (6 steps, notes never opened) 171–484 ms, median ≈ 350; blank frames first in 4 of 6 1–11 ms (same task as the key); about 180 ms only when nothing was remembered yet
Hold ↓ for 3 s at 30/s, 10k Home: frames showing the picked note in full 0 % (12 frames, all blank) 92 %, 0 blank (1 title-only)
e2e @perf hold (80 notes plus a 2,000-line note) 2 frames in 3 s, 0 % full, frames 1,050 ms 22 frames, 100 % full, 0 blank, frame p50 16.7 ms (p95 483 ms on this loaded box)
Main-thread CPU per step (trace, 40 steps, each waited out until shown) 49.6 ms (JS 30.8, layout 6.5) 26.9 ms (JS 19.0, layout 5.0)
Main-thread CPU per step while holding (60 steps, 20 ms apart) – 22.0 ms (JS 16.7, of which ~5 is the layout the frame needs anyway)
Wall, key → full text (40 steps, contended) p50 584, p95 1,641 ms p50 98, p95 283 ms
Room joins / IndexedDB database opens while holding ↓ 1 join + 2 opens per note none until the selection rests 150 ms

What's left on this box: when the main thread is saturated, Chrome runs input before timers and network replies. The prefetch now asks straight away whenever one of the next few notes has no text, so it no longer waits on a timer. Frame p95 on CI here mostly reflects the rasteriser; the gate in the @perf test (≥ 98 % full frames, p95 < 50 ms on Chromium) is meant for the quiet perf machine.

Screenshots (10k Home, a note reached with ↓, after a tap on the phone)

chromium, light: 1440 · 900 · 390

chromium-1440-light chromium-900-light chromium-390-light

chromium, dark: 1440 · 900 · 390

chromium-1440-dark chromium-900-dark chromium-390-dark

webkit, light: 1440 · 900 · 390

webkit-1440-light webkit-900-light webkit-390-light

webkit, dark: 1440 · 900 · 390

webkit-1440-dark webkit-900-dark webkit-390-dark

Frame strip: four ↓ presses, each captured right after its key (full note every time)

key 1 key 2 key 3 key 4

Frame strip: opening with the mouse, the fade held at 0 / 35 / 70 / 105 / 140 ms (opacity only, nothing moves)

0 ms 35 ms 70 ms 105 ms 140 ms

## Before / after (PR #243) Setup: the 10k Home, a release server and a production build in headless Chromium at 1440. The build box sat at load 60–120 on 12 cores throughout, so the browser ran at `nice -15`. Wall-clock frame times here are mostly the software rasteriser fighting for CPU, which is why the main-thread **CPU** numbers (trace `tdur`) are the fair comparison. Before = dev at the start of this issue; after = this PR. | | before | after | |---|---|---| | One ↓ step: key → picked note shown in full (6 steps, notes never opened) | 171–484 ms, median ≈ 350; blank frames first in 4 of 6 | **1–11 ms** (same task as the key); about 180 ms only when nothing was remembered yet | | Hold ↓ for 3 s at 30/s, 10k Home: frames showing the picked note in full | **0 %** (12 frames, all blank) | **92 %**, 0 blank (1 title-only) | | e2e `@perf` hold (80 notes plus a 2,000-line note) | 2 frames in 3 s, 0 % full, frames 1,050 ms | 22 frames, **100 % full**, 0 blank, frame p50 **16.7 ms** (p95 483 ms on this loaded box) | | Main-thread CPU per step (trace, 40 steps, each waited out until shown) | 49.6 ms (JS 30.8, layout 6.5) | **26.9 ms** (JS 19.0, layout 5.0) | | Main-thread CPU per step while holding (60 steps, 20 ms apart) | – | **22.0 ms** (JS 16.7, of which ~5 is the layout the frame needs anyway) | | Wall, key → full text (40 steps, contended) | p50 584, p95 1,641 ms | p50 98, p95 283 ms | | Room joins / IndexedDB database opens while holding ↓ | 1 join + 2 opens per note | none until the selection rests 150 ms | What's left on this box: when the main thread is saturated, Chrome runs input before timers and network replies. The prefetch now asks straight away whenever one of the next few notes has no text, so it no longer waits on a timer. Frame p95 on CI here mostly reflects the rasteriser; the gate in the `@perf` test (≥ 98 % full frames, p95 < 50 ms on Chromium) is meant for the quiet perf machine. ### Screenshots (10k Home, a note reached with ↓, after a tap on the phone) **chromium, light:** 1440 · 900 · 390 ![chromium-1440-light](https://git.kayg.org/attachments/bf975e12-1695-4435-beda-2f9fa1202dda) ![chromium-900-light](https://git.kayg.org/attachments/877cfbc9-e2cf-4712-b5df-52f214dd2f28) ![chromium-390-light](https://git.kayg.org/attachments/89604ba3-5fdf-42bd-8750-b0a1e70e830f) **chromium, dark:** 1440 · 900 · 390 ![chromium-1440-dark](https://git.kayg.org/attachments/d5caf24d-4df3-4ed4-aa59-62516ff18579) ![chromium-900-dark](https://git.kayg.org/attachments/7b1c9360-24e6-4299-a8e2-219c2658ea36) ![chromium-390-dark](https://git.kayg.org/attachments/f99839e3-1148-492d-8630-2cc71f640084) **webkit, light:** 1440 · 900 · 390 ![webkit-1440-light](https://git.kayg.org/attachments/cce7ce9e-0152-406b-b4ea-c8ffcf48b996) ![webkit-900-light](https://git.kayg.org/attachments/e7cb45e0-0faf-4e40-9d6b-437d2549e87d) ![webkit-390-light](https://git.kayg.org/attachments/a3a9aa1f-8831-432d-bb8b-b652537ab1b9) **webkit, dark:** 1440 · 900 · 390 ![webkit-1440-dark](https://git.kayg.org/attachments/1d54b2a7-3019-4b1e-a33a-b6401712aed2) ![webkit-900-dark](https://git.kayg.org/attachments/c6cb3a88-235c-4327-81ae-5c3287cdc86f) ![webkit-390-dark](https://git.kayg.org/attachments/ef2bc738-1c9d-406b-9ac3-7d77fb4ccbdd) ### Frame strip: four ↓ presses, each captured right after its key (full note every time) ![key 1](https://git.kayg.org/attachments/bd04d273-8294-4c65-b827-a97f73baf6d4) ![key 2](https://git.kayg.org/attachments/3187341e-b468-4cde-92ba-bfab7977e142) ![key 3](https://git.kayg.org/attachments/58a1e4f2-b422-42bf-8339-1fd3431fcf96) ![key 4](https://git.kayg.org/attachments/f586aa14-e29b-4d8b-96d8-e1b6d536e624) ### Frame strip: opening with the mouse, the fade held at 0 / 35 / 70 / 105 / 140 ms (opacity only, nothing moves) ![0 ms](https://git.kayg.org/attachments/1a140a63-68d2-484f-bc0c-9a22df61d1e7) ![35 ms](https://git.kayg.org/attachments/e069ce4f-9c03-42db-bc04-e971f29bd59c) ![70 ms](https://git.kayg.org/attachments/55e3a626-382d-4343-853c-358255457eb6) ![105 ms](https://git.kayg.org/attachments/9420a0f8-8e10-4acd-b01a-394c609e9aaa) ![140 ms](https://git.kayg.org/attachments/13a867eb-0431-4dca-a385-881d11be3028)
kayg closed this issue 2026-10-14 12:15:55 +00:00
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#150
No description provided.