Skip to content

Speed up large Reader libraries and long-article highlight painting - #360

Merged
callumalpass merged 2 commits into
mainfrom
offline-reopen-performance
Nov 28, 2026
Merged

callumalpass merged 2 commits into
mainfrom
offline-reopen-performance

Conversation

@callumalpass

Copy link
Copy Markdown
Member

Reader now builds the source command list when the palette opens, sorts an unfiltered title snapshot directly and compares each distinct tag once per filter. Paged annotation search validates a resolved owner ID once per record path. Drawing a highlight can use the first match of the full normalized quote and its surrounding context. Strict search still checks ambiguity, and partially matching or edited quotes still use the scored matcher.

Chromium measurements

Compared with cb7ff1e5fcbcdfa1b29fe7d2d2c442bdf946a5a9 on the same workstation. One warm-up pair and nine measured pairs per size, with the order reversed each pair. Chromium 156.0.8078.4. Times are milliseconds. p95 is the nearest-rank p95 across nine observations (the maximum). The startup fixture mounts the virtualized Reader workspace in a 1280 × 900 viewport. The response-to-grid row starts after the synthetic library HTTP response finishes. The other rows run in a separate Chromium page. Local operation batches average 100 calls for the 100-source control and eight for the large library. Each article sample uses a fresh runtime.

10,000 sources

Operation Before median After median Before p95 After p95
Startup to virtualized grid 4731.90 3441.60 6252.40 8182.80
Library response to grid 1155.60 824.20 1821.70 2119.10
Sort fresh title snapshot 10.70 8.96 35.72 21.57
Filter title order by metadata and tag 10.93 8.61 25.35 41.69
Rank tag suggestions 1.10 0.95 2.64 9.16
Group source-note and annotation search hits 20.31 15.02 66.52 98.57
Sanitize and lay out 3k HTML paragraphs 202.50 237.40 419.30 1099.90
Anchor and paint 600 unique highlights 234.10 122.90 500.10 374.10
Anchor and paint 600 repeated highlights 209.30 121.90 452.90 261.50

100 sources

Operation Before median After median Before p95 After p95
Startup to virtualized grid 1965.00 1861.80 3555.80 4193.10
Library response to grid 332.90 360.90 741.00 435.30
Sort fresh title snapshot 0.04 0.02 0.10 0.06
Filter title order by metadata and tag 0.03 0.03 0.09 0.23
Rank tag suggestions 0.05 0.05 0.24 0.31
Group source-note and annotation search hits 0.15 0.19 0.44 0.44

The large-library medians improved for startup, title sort, metadata/tag filtering, tag ranking and grouped search. Unique and repeated highlight painting also improved at p95. Startup, filtering, tags and search had higher large-library p95s in this run. The unchanged sanitizer/layout control was slower at both percentiles. The shared machine had load averages above 40 on 16 logical CPUs during the run, so these observations do not establish a tail-latency improvement across the library.

Search measures grouping and passage extraction from preselected SDK pages containing one source note and ten annotations per owner. It excludes authority query execution and network latency. Tag suggestions use Reader’s existing 2,000-source sampling limit. The long article has 3,000 paragraphs. The fixture checks all 600 highlight positions in each distribution and confirms that inline handlers are removed and the last paragraph lays out.

Reproduce

From this PR's checkout, install both revisions and copy the identical browser fixture into a temporary baseline tree.

pnpm install --frozen-lockfile
base=$(mktemp -d)
git archive cb7ff1e5fcbcdfa1b29fe7d2d2c442bdf946a5a9 | tar -x -C "$base"
cp apps/reader/test-fixtures/library-article-benchmark.tsx "$base/apps/reader/test-fixtures/"
(cd "$base" && pnpm install --frozen-lockfile)
pnpm --filter @mdbase-reader/app exec playwright install chromium
(cd "$base/apps/reader" && MDBASE_ENV=production pnpm exec vite --host 127.0.0.1 --port 5385 --strictPort) &
(cd apps/reader && MDBASE_ENV=production pnpm exec vite --host 127.0.0.1 --port 5386 --strictPort) &
# Once both servers are ready
READER_BASELINE_ORIGIN=http://127.0.0.1:5385 READER_AUDIT_ORIGIN=http://127.0.0.1:5386 \
  node apps/reader/scripts/benchmark-library-article.mjs
node apps/reader/scripts/audit-library-article.mjs
rpnpm check
rpnpm build:production

Offline investigation

The production report observed locally readable annotations and an article retry screen after an offline reload. It did not capture the retry text or failed operation. Source inspection shows Reader resolves current file metadata and streams the attachment through the SDK. Reload discards its in-memory object URL. Durable attachment availability remains an SDK question under the storage policy documented in docs/offline-shell.md. This performance PR makes no production offline-reopen claim.

@callumalpass
callumalpass enabled auto-merge (squash) November 28, 2026 13:24
@callumalpass
callumalpass merged commit 7f64f87 into main Nov 28, 2026
3 checks passed
@callumalpass
callumalpass deleted the offline-reopen-performance branch November 28, 2026 13:30
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