Skip to content

Reduce Reader library hydration and long article setup work - #361

Merged
callumalpass merged 1 commit into
mainfrom
reader-search-render-performance
Nov 28, 2026
Merged

callumalpass merged 1 commit into
mainfrom
reader-search-render-performance

Conversation

@callumalpass

Copy link
Copy Markdown
Member

Refs #268

Changes

  • Request larger SDK source-contract pages where supported, map SDK-verified projection records by position, and reuse the completed in-memory workspace snapshot. Older replicas retain the SDK's 128-record cap.
  • Reuse title order for repeated library filters, skip annotation-owner resolution on note-only pages, and prepare annotation-list search text on demand. ArrowDown reaches a mounted row after the previous tab stop scrolls out of the virtualized grid.
  • Reuse sanitized copies of repeated SVGs within one HTML document and stop TOC availability checks after two usable headings. The existing single library search, HTML sandbox and SDK-owned offline collection storage are preserved.

Paired Chromium measurements

Baseline 7f64f870ae4ccf979e2cff27d7241221b5cf2e50 and candidate 023dda30c0a02e3e88a0a0531b90c96c6d9a0771, using the same two fixtures. Nine alternating pairs per library size after one warm-up. Each cell shows baseline median / p95 → candidate median / p95, in milliseconds. With nine samples, p95 is the slowest observed run. The component timings use local stubbed SDK responses and include a timer turn per contract page. The browser timings use loopback fixtures with synthetic data. Live replica latency and production deployment were outside this run.

Chromium 156.0.8078.4. The largest gains were in the 10,000-source contract walk (79 → 20 simulated requests), status switching, repeated-SVG sanitization, and TOC availability checks. The run recorded slower body-search medians, a slower first contract page, and a higher 10,000-source article-open p95. It did not establish a general search or article-open speedup.

Operation 100-source control 10,000 sources
Startup to virtualized grid 1112.1 / 1534.4 → 1217.2 / 1705.7 1185.9 / 1826.8 → 1048.8 / 1490.3
Library response to grid 273.5 / 388.8 → 269.4 / 324.2 347.9 / 435.2 → 299.6 / 402.9
Virtualized scroll to target row 97.2 / 219.2 → 87.8 / 113.2 96.4 / 192.9 → 85.9 / 99
Open article to first usable iframe 508.4 / 1059.5 → 447.6 / 576.8 494.8 / 593.3 → 473.1 / 1004.9
Open annotation sidebar (600 highlights) 36.3 / 87.6 → 43.3 / 89.7 31.5 / 126.3 → 34.9 / 39.5
First workspace page 1 / 1.5 → 1.2 / 6.7 1.1 / 1.4 → 1.5 / 5.4
Cold paged workspace hydration 1.1 / 1.6 → 1.2 / 6.7 321 / 344.7 → 70.2 / 80.4
Warm workspace library read 0 / 0.001 → 0 / 0.001 0.014 / 0.033 → 0 / 0.001
Sort fresh title snapshot 0.018 / 0.027 → 0.023 / 0.048 2.762 / 6.912 → 3.837 / 7.362
Filter title order by metadata and tag 0.016 / 0.063 → 0.026 / 0.066 2.95 / 4.162 → 3.013 / 5.9
Switch three status buckets 0.02 / 0.039 → 0.01 / 0.058 2.663 / 4.675 → 1.637 / 4
Rank tag suggestions 0.037 / 0.046 → 0.034 / 0.054 0.3 / 0.588 → 0.3 / 0.463
Group source-note and annotation search hits 0.069 / 0.141 → 0.094 / 0.258 7.2 / 9.087 → 8.563 / 12.813
Search source-note bodies 0.016 / 0.036 → 0.018 / 0.042 1.075 / 1.488 → 1.225 / 2.813
Search annotation bodies 0.066 / 0.146 → 0.095 / 0.282 5.112 / 6.125 → 6.162 / 19.488
Sanitize long HTML 13.2 / 18.575 → 16.875 / 31.55 11.375 / 15.025 → 13.975 / 22.3
Sanitize HTML with 64 repeated SVGs 27.2 / 34.15 → 18.025 / 27.6 23.475 / 42.825 → 14.8 / 24.35
Load and lay out long HTML iframe 80.9 / 107.3 → 106 / 172.5 92.4 / 116.3 → 93.3 / 222.3
Extract long article TOC 0.295 / 0.87 → 0.45 / 0.63 0.25 / 0.455 → 0.305 / 0.54
Check long article TOC availability 0.35 / 0.588 → 0.3 / 0.363 0.363 / 0.625 → 0.225 / 0.375
Anchor and paint 600 unique highlights 88.6 / 103.3 → 101.9 / 136.1 88.8 / 117.3 → 92.9 / 116.3
Anchor and paint 600 repeated highlights 76.8 / 100.4 → 83.5 / 112.7 73.4 / 106.6 → 81.4 / 105.5

Reproduce

From the PR checkout, create a separate baseline worktree and apply the fixture-only changes.

baseline=/tmp/reader-w17-baseline
base=7f64f870ae4ccf979e2cff27d7241221b5cf2e50
git worktree add --detach "$baseline" "$base"
git diff "$base" HEAD -- apps/reader/test-fixtures/annotation-scale.tsx apps/reader/test-fixtures/library-article-benchmark.tsx |
  git -C "$baseline" apply
pnpm install --frozen-lockfile
pnpm -C "$baseline" install --frozen-lockfile
pnpm --filter @mdbase-reader/app exec playwright install chromium

Run these Vite commands in separate terminals, then run the comparison from the PR checkout.

pnpm -C "$baseline" --filter @mdbase-reader/app exec vite --host 127.0.0.1 --port 5312 --strictPort
pnpm --filter @mdbase-reader/app exec vite --host 127.0.0.1 --port 5311 --strictPort
READER_BASELINE_ORIGIN=http://127.0.0.1:5312 READER_AUDIT_ORIGIN=http://127.0.0.1:5311 READER_BENCH_PAIRS=9 \
  node apps/reader/scripts/benchmark-library-article.mjs

Verification

  • rpnpm check passed, including lint, typecheck, workspace and repository tests, and catalogue validation.
  • rpnpm build:production and local MDBASE_ENV=production pnpm build passed. Local git status --porcelain was empty before and after the build.
  • Local Chromium library and article, mobile library, and imported SVG audits passed.

@callumalpass
callumalpass enabled auto-merge (squash) November 28, 2026 14:19
@callumalpass
callumalpass merged commit ca407c0 into main Nov 28, 2026
3 checks passed
@callumalpass
callumalpass deleted the reader-search-render-performance branch November 28, 2026 14:26
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