Skip to content

Speed up Writer manuscript hydration and chapter switching - #255

Merged
callumalpass merged 1 commit into
mainfrom
optimize-chapter-hydration-switching
Nov 28, 2026
Merged

callumalpass merged 1 commit into
mainfrom
optimize-chapter-hydration-switching

Conversation

@callumalpass

@callumalpass callumalpass commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Changes

  • Request larger native contract pages for sources and annotations to reduce repeated projection queries during manuscript discovery. The SDK applies the replica's page-size limit, and Writer retries oversized pages at half size.
  • Skip work in unchanged Sources content and outline rows when switching chapters. Recompute citation locations when the records or reading order change.
  • Wait for the final unavailable-type notice in the asynchronous Home test.

Chromium comparison

The baseline CPU capture spent about 2.3 seconds under the in-memory SDK's contract projection handler during large-fixture hydration. The switch trace also showed React work in the workspace and outline.

Seven alternating baseline and candidate pairs at each fixture size, against e56c6980a0f0f2b9b4b9178ded4519902d389775. Chromium 149.0.7827.55, Node 22.22.0 and the pinned production SDK 0.2.61, using local Vite development servers and in-memory demo collections. The large fixture has 120 chapter references, 5,000 sources and 30,000 annotations. Hydration includes navigation, fixture seeding, index and outline readiness, and settling every chapter open. The SDK permits 64 record sessions in this fixture. The main record and 63 chapters open, and Writer reports 57 refused opens on both revisions.

Metric (ms) 120 chapters median 120 chapters p95 2 chapters median 2 chapters p95
Index ready 11,292.7 → 6,576.5 12,728.9 → 9,205.5 1,384.9 → 1,073.3 2,157.2 → 1,640.3
Hydration 11,386.7 → 6,717.5 12,852.2 → 9,411.3 1,459.4 → 1,120.1 2,215.1 → 1,718.7
Preview with bibliography 13,366.2 → 8,204.7 14,918.5 → 12,367.2 2,520.5 → 1,914.0 2,908.7 → 3,191.8
Switch out and back 354.3 → 326.0 638.8 → 689.3 191.6 → 173.8 350.6 → 258.8
Open cited Sources panel 594.6 → 586.6 849.7 → 891.4 457.4 → 388.9 778.5 → 611.3
Source filter 157.4 → 161.8 343.5 → 467.5 51.1 → 157.6 117.6 → 200.5
Outline search 74.1 → 83.2 143.5 → 505.2 47.6 → 45.6 189.0 → 83.3
Citation completion 285.5 → 280.7 346.8 → 556.9 160.8 → 130.1 201.8 → 333.7
Accept citation 380.8 → 379.5 630.8 → 623.0 122.6 → 52.1 228.3 → 235.3
Type and checkpoint 807.2 → 950.6 1,246.9 → 1,518.8 545.0 → 573.1 779.6 → 1,525.0
Typing renderer CPU 825.3 → 917.8 1,176.8 → 1,399.0 519.8 → 546.9 731.7 → 1,091.6
Confirmed save after checkpoint 1,147.5 → 1,110.6 1,224.5 → 1,411.3 1,209.3 → 1,219.3 1,292.3 → 1,337.5

Values are baseline → candidate. The nearest-rank p95 is the maximum of seven observations. Large hydration improved in all seven pairs and switching in five. The large switch, completion and checkpoint p95 rose. The two-chapter source filter was slower in all seven primary pairs. A separate seven-pair probe showed mixed results and a +0.4 ms median paired end-to-end difference. The input-to-result DOM median in that probe was 34.5 → 48.6 ms.

Reproduce

Start each server in its own checkout with dependencies installed from the lockfile. Use the benchmark driver in the candidate checkout.

# Baseline checkout
VITE_MDBASE_ENV=production pnpm -C apps/writer dev --port 5377

# Candidate checkout, in another shell
VITE_MDBASE_ENV=production pnpm -C apps/writer dev --port 5378

# Candidate checkout, after both servers are ready
BASELINE=http://127.0.0.1:5377 BASE=http://127.0.0.1:5378 PROFILE_CHAPTERS=120 \
  pnpm -C apps/writer exec node scripts/perf/interactive-profile.mjs > paired.jsonl

See the performance README for the fixture assertions and optional CPU capture.

Verification

  • rpnpm check
  • rpnpm build:production
  • rpnpm --filter @mdbase-writer/app typecheck:perf
  • The 60-chapter Chromium Word-export check verified every chapter passage, the overlapping edit, bibliography and footnote. All 16 uncompressed DOCX parts matched after normalizing creation and modification timestamps.
  • Production-SDK Chromium reliability passed all 25 cases, including draft recovery and chapter-switch history and scroll.
  • Default-SDK Chromium accessibility passed all 90 axe scans and the focus-return checks. The primary, Round 2, Round 6, Round 6 review and Round 8 polish scripts passed locally.
  • The local Round 4 desktop sidebar gate exceeded its 50 ms budget in four variants (medians of 145, 53, 197 and 80 ms). Round 7 stopped at its host-load guard. On a quieter GCP desk with the same Chromium version, the focused baseline Round 4 case, the full candidate Round 4 matrix and the candidate Round 7 script passed. Each candidate desktop variant recorded zero long tasks across five sidebar hides.

@callumalpass
callumalpass merged commit bc2cb75 into main Nov 28, 2026
1 check passed
@callumalpass
callumalpass deleted the optimize-chapter-hydration-switching branch November 28, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant