perf: lazy @codemirror/autocomplete with idle preload (first paint −7 KB) #975

Closed
kayg wants to merge 0 commits from perf/lazy-autocomplete into dev
Owner

perf: @codemirror/autocomplete leaves first paint

The [[, @ and # list's library is about 7 KB of the page that opens the app and nobody needs it before typing a trigger.

  • transforms/picker.ts (first paint) keeps only the [[Title]] close handler, a Compartment, a trigger sniffer and an idle hook. The list (picker-list.ts, tags.ts, the library) is its own chunk picker-list, fetched at the first idle moment after the editor mounts, or at once on the first [, @ or # if that comes sooner; then a list is opened for what was typed meanwhile (kick). No keystroke is swallowed.
  • links.ts imports the completion types as import type (the inline type form left a side-effect import of the library behind).
  • lang-markdown imported the library for markdown()'s HTML tag completion, which the app never calls; scripts/no-markdown-completion-plugin.ts gives that one import an empty stand-in (same pattern as no-remote-selections).
  • Budgets: new picker-list line 9.7 KB, taken from the index line (total unchanged); idle-screens 51.3 → 51.6 from the same line (dev itself measures 51.334 against 51.3).

Gates and measurements are in the comments below.

🤖 Generated with Claude Code

## perf: `@codemirror/autocomplete` leaves first paint The `[[`, `@` and `#` list's library is about 7 KB of the page that opens the app and nobody needs it before typing a trigger. - `transforms/picker.ts` (first paint) keeps only the `[[Title]]` close handler, a Compartment, a trigger sniffer and an idle hook. The list (`picker-list.ts`, `tags.ts`, the library) is its own chunk `picker-list`, fetched **at the first idle moment after the editor mounts**, or **at once on the first `[`, `@` or `#`** if that comes sooner; then a list is opened for what was typed meanwhile (`kick`). No keystroke is swallowed. - `links.ts` imports the completion types as `import type` (the inline `type` form left a side-effect import of the library behind). - `lang-markdown` imported the library for `markdown()`'s HTML tag completion, which the app never calls; `scripts/no-markdown-completion-plugin.ts` gives that one import an empty stand-in (same pattern as `no-remote-selections`). - Budgets: new `picker-list` line 9.7 KB, taken from the `index` line (total unchanged); `idle-screens` 51.3 → 51.6 from the same line (dev itself measures 51.334 against 51.3). Gates and measurements are in the comments below. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

#975 gates: GREEN at d6e3e934 (dev 02cdf878 merged)

gate result
lint / svelte-check / vitest web / ui primitives / vitest editor pass / 0 errors, 16 warnings (= dev) / 109 / 56 / 511 (40 files)
check-ui-primitives clean
first-paint JS brotli (perf/web.sh --bundle-only --gate, same machine) 225.535 KB vs dev 232.617: −7.08 KB (−3.0 %); first CSS 17.952 = dev. The library (+ list code) is the new picker-list chunk, 9.25 KB, not in first paint
budgets new picker-list line 9.7 KB and idle-screens 51.3 → 51.6 (dev itself measures 51.334 on 51.3), both taken from the index line (239.2 → 229.2): total stays 404.2. Gate rc 0
Chromium (dev-01) 1440+390: picker, link-suggest, tag-picker, tags, editor, vim, missing-links, preload, lazy-ui, lazy-styled, keyboard, note-pills, select-rows, composer, bar-focus 205 passed, 0 failed
WebKit (dev-02) same 172 passed, 0 failed
new picker-lazy.spec.ts (chunk held back 2 s: a [[ typed before it arrives keeps its words and opens the list when it does; [[Title]] finished by hand works before it arrives) 4/4 pass on Chromium and WebKit, 1440 + 390
Rust n/a

Mac VM, WebKit (Playwright's WebKit build on macOS with the GPU, not Safari.app), first [[ popup, keydown to the frame with rows, ABAB, 3 rounds × 15 fresh page loads, first of each round dropped (n = 42 per cell), dev 02cdf878 vs this head:

after load dev p25 / p50 / p95 (ms) #975 p25 / p50 / p95 Mann–Whitney z
1 s 167 / 178 / 367 165 / 175 / 506 1.27
3 s 175 / 179 / 208 173 / 184 / 232 0.26
10 s 183 / 190 / 209 180 / 188 / 213 0.92

Trimmed mean of the fastest 80 %: 1 s 177 vs 172, 3 s 179 vs 179, 10 s 188 vs 186. No cell differs (|z| < 1.3); the p95 at 1 s (506 vs 367) and 3 s are single slow loads on both sides (dev has 2796, 1109 and 756 ms outliers at 1 s; the PR has 909 and a 18.9 s stall in an earlier run, the Mac VM stalls). Typing, keydown to next frame, 450 keys per run at 10 s: p50 10–11 ms both; p95 27–28 dev vs 25–28 PR. Flat. The chunk is warm by 1 s: it loads on the first idle moment (a 200 ms timer in Safari, which has no requestIdleCallback), or at once on the first [, @ or #.

## #975 gates: GREEN at `d6e3e934` (dev `02cdf878` merged) | gate | result | |---|---| | lint / svelte-check / vitest web / ui primitives / **vitest editor** | pass / 0 errors, 16 warnings (= dev) / 109 / 56 / **511 (40 files)** | | `check-ui-primitives` | clean | | **first-paint JS brotli** (`perf/web.sh --bundle-only --gate`, same machine) | **225.535 KB vs dev 232.617: −7.08 KB (−3.0 %)**; first CSS 17.952 = dev. The library (+ list code) is the new `picker-list` chunk, 9.25 KB, not in first paint | | budgets | new `picker-list` line 9.7 KB and `idle-screens` 51.3 → 51.6 (dev itself measures 51.334 on 51.3), both taken from the `index` line (239.2 → 229.2): total stays 404.2. Gate rc 0 | | Chromium (dev-01) 1440+390: picker, link-suggest, tag-picker, tags, editor, vim, missing-links, preload, lazy-ui, lazy-styled, keyboard, note-pills, select-rows, composer, bar-focus | 205 passed, 0 failed | | WebKit (dev-02) same | 172 passed, 0 failed | | new `picker-lazy.spec.ts` (chunk held back 2 s: a `[[` typed before it arrives keeps its words and opens the list when it does; `[[Title]]` finished by hand works before it arrives) | 4/4 pass on Chromium and WebKit, 1440 + 390 | | Rust | n/a | **Mac VM, WebKit (Playwright's WebKit build on macOS with the GPU, not Safari.app), first `[[` popup, keydown to the frame with rows**, ABAB, 3 rounds × 15 fresh page loads, first of each round dropped (n = 42 per cell), dev `02cdf878` vs this head: | after load | dev p25 / p50 / p95 (ms) | #975 p25 / p50 / p95 | Mann–Whitney z | |---|---|---|---| | 1 s | 167 / 178 / 367 | 165 / 175 / 506 | 1.27 | | 3 s | 175 / 179 / 208 | 173 / 184 / 232 | 0.26 | | 10 s | 183 / 190 / 209 | 180 / 188 / 213 | 0.92 | Trimmed mean of the fastest 80 %: 1 s 177 vs 172, 3 s 179 vs 179, 10 s 188 vs 186. No cell differs (|z| < 1.3); the p95 at 1 s (506 vs 367) and 3 s are single slow loads on both sides (dev has 2796, 1109 and 756 ms outliers at 1 s; the PR has 909 and a 18.9 s stall in an earlier run, the Mac VM stalls). Typing, keydown to next frame, 450 keys per run at 10 s: p50 10–11 ms both; p95 27–28 dev vs 25–28 PR. Flat. The chunk is warm by 1 s: it loads on the first idle moment (a 200 ms timer in Safari, which has no `requestIdleCallback`), or at once on the first `[`, `@` or `#`.
Author
Owner

Merged into dev by the orchestrator (U1 GREEN).

Merged into dev by the orchestrator (U1 GREEN).
kayg closed this pull request 2026-11-06 00:20:24 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled

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!975
No description provided.