Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/writer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"typecheck": "pnpm manifest && tsc -p tsconfig.json",
"deploy:lab": "MDBASE_ENV=lab node scripts/deploy-pages.mjs",
"upload:compiler": "node scripts/upload-compiler.mjs",
"test:perf-fixture": "PERF_RUNS=1 PERF_LATENCY_MS=0 vitest run --config scripts/perf/vitest.config.ts",
"typecheck:perf": "tsc -p scripts/perf/tsconfig.json"
"test:perf-fixture": "pnpm manifest && PERF_RUNS=1 PERF_LATENCY_MS=0 vitest run --config scripts/perf/vitest.config.ts",
"typecheck:perf": "pnpm manifest && tsc -p scripts/perf/tsconfig.json"
},
"dependencies": {
"@codemirror/autocomplete": "^6.20.3",
Expand Down
61 changes: 57 additions & 4 deletions apps/writer/scripts/perf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,28 @@ rpnpm --filter @mdbase-writer/app typecheck:perf
pnpm -C apps/writer typecheck
```

The registered smoke check runs one zero-latency fixture with `rpnpm --filter @mdbase-writer/app test:perf-fixture`.
Run both benchmarks with `rpnpm --filter @mdbase-writer/app test:perf-fixture`. This uses one zero-latency run of the collection fixture.

Run just the mounted outline benchmark from the repository root:

```sh
rpnpm --filter @mdbase-writer/app run test:perf-fixture scripts/perf/outline.bench.tsx
```

It renders all 120 chapter rows through the normal outline pagination, edits one chapter, and switches among four loaded chapters. It checks section words and searches for one sparse term and one broad term across the same manuscript. Each phase has 5 warmups and 20 measurements. The fixture has 24 headings and three comment offsets per chapter. Outline timings include React commits in jsdom.

For a control at `ba47bda`, create a detached worktree and copy these files from the performance branch before running the same commands. Start the dev server from that worktree for the Chromium comparison.

```text
apps/writer/package.json
apps/writer/scripts/perf/browser-profile.mjs
apps/writer/scripts/perf/generator.ts
apps/writer/scripts/perf/outline.bench.tsx
apps/writer/scripts/perf/tsconfig.json
apps/writer/scripts/perf/vitest.config.ts
apps/writer/src/backend/large-demo.ts
apps/writer/src/ui/DemoRoot.tsx
```

Capture JSON (output path is relative to `apps/writer`):

Expand Down Expand Up @@ -37,6 +58,17 @@ Result JSON is generated evidence: the default is `out/perf/large-collection.jso

## Recorded outcomes

Outline comparison on the remote builder (AMD EPYC 9B14, Node 22.22.0). The two revisions ran the same outline benchmark three times each, with Writer at `ba47bda` for the control. The p50 columns are medians of the three runs. The p95 columns show the spread across runs.

| Operation | Before p50 | After p50 | Before p95 range | After p95 range |
|---|---:|---:|---:|---:|
| Typing in one chapter | 19.97 ms | 16.76 ms | 21.66–49.75 ms | 19.00–47.49 ms |
| Switching chapters | 21.98 ms | 18.57 ms | 20.45–60.42 ms | 18.89–19.30 ms |
| Sparse manuscript search (1 hit) | 1.31 ms | 1.31 ms | 1.32–1.40 ms | 1.32–1.33 ms |
| Broad manuscript search (34,560 hits) | 2.46 ms | 2.38 ms | 2.87–4.62 ms | 2.68–2.77 ms |

In one zero-latency collection run, warm search over 5,000 sources took 0.73 ms median, and resolving paths for 100 chapter embeds took 0.25 ms median. Cached placement of 300 comments took 0.03 ms, cold placement across 3,000 comments took 10.06 ms, and server rendering the Comments panel took 24.78 ms. Scanning 100 records from scratch for words, labels, and citations took 21.85 ms. Writer already tracks those manuscript totals by changed body. The outline change reuses heading parses and section counts across edits and chapter switches.

Round 3, three-run 20 ms medians (before → after):

| Metric | Before | After |
Expand All @@ -57,14 +89,16 @@ Round 5 keeps the incremental traffic totals above, selected-body batching and w

## Chromium responsiveness profile (Round 4)

Start the normal development server, then visit `http://127.0.0.1:5320/?demo=large&manuscript=manuscripts/main.md`. This mode shares `generator.ts` with the Node benchmark; it adds 100 labelled headings, 300 highlights on one source and one 149-reply thread. It uses NativeWriterBackend, SDK sessions, compiler and renderer over an in-memory SDK fixture. It is DEV-only, even for a production demo build.
Start the normal development server, then visit `http://127.0.0.1:5320/?demo=large&largeManuscript=1&manuscript=manuscripts/main.md`. This mode shares `generator.ts` with the Node benchmark. The Chromium fixture adds 60 embedded chapters, 100 labelled main-record headings, 300 highlights on one source and one 149-reply thread. It uses NativeWriterBackend, SDK sessions, compiler and renderer over an in-memory SDK fixture. It is DEV-only, even for a production demo build.

A 120-chapter attempt with SDK 0.2.58 opened the main record and 63 chapters. The SDK refused the other 57 with `record_session_budget` because Writer retains a session for each embedded chapter. The browser fixture uses 60 chapters so it can exercise the complete manuscript. The 120-chapter outline benchmark supplies record views directly.

```sh
PROFILE_NAME=after PROFILE_OUTPUT=out/perf/browser-after.json pnpm -C apps/writer exec node scripts/perf/browser-profile.mjs
pnpm -C apps/writer test:browser
```

`BASE`, `CHROME`, `PROFILE_NAME`, `PROFILE_OUTPUT` are configurable.
`BASE`, `CHROME`, `PROFILE_NAME`, and `PROFILE_OUTPUT` are configurable. Set `PROFILE_EDITOR_ONLY=1` to measure editing with the preview pane hidden.
HTTP cache is explicitly disabled and service workers bypassed on every profile.
The profiler now also captures startup tasks, first drawn-revision time, worker
messages/resource timings, main heap after forced GC/full discovery and worker
Expand All @@ -78,9 +112,28 @@ pnpm -C apps/writer exec node scripts/perf/heap-summary.mjs out/perf/main.heapsn
COLD_CACHE=1 pnpm -C apps/writer test:browser
```

### 60-chapter Chromium comparison

Both runs used `PROFILE_EDITOR_ONLY=1` on an AMD Ryzen 9 7940HS with Node 22.22.0 and Playwright's Chromium. The split-view attempts timed out while returning to the main record. The editor-only pair edited a chapter and used the export controls for the full workspace. Each run loaded 60 chapters, 300 comment records, and 5,000 sources. Comments showed 50 threads and 50 replies in both runs.

| Action | Before | After |
|---|---:|---:|
| Switch through four chapters | 4.17 s | 2.46 s |
| Type with Outline open | 1.81 s | 1.19 s |
| Type with Comments open | 2.41 s | 1.68 s |
| Type with Sources open | 1.01 s | 1.22 s |
| Filter sources | 288 ms | 98 ms |
| Sparse outline search (1 result) | 272 ms | 730 ms |
| Broad outline search (480 results) | 761 ms | 461 ms |
| Download Word document | 43.15 s | 44.39 s |

Both exports produced a 27,086-byte DOCX containing the Word document part. The two browser runs had long tasks above 20 seconds around export and source interactions. The browser measurements are single observations. The repeated Vitest runs establish the outline comparison.

### Earlier browser measurements

On the fixture-corrected product comparison, cold preview went from 3,426 to
2,134 ms and the GC-controlled main heap from 60.91 to 58.28 MiB.
Uncollected heap is still recorded for historical comparisons, not treated as a
retention measurement.

The script also captures editor/preview visible geometry at animation frames, CDP main-isolate JS heap, >50 ms main-thread long tasks during two ~10 s typing phases, source paging (historically Show all), 300-highlight expansion, citation/embed completion, page errors and `out/large-{sources,comments}-{before,after}.png`. One run is observational, not a statistical timing assertion; the main heap field excludes workers/native backing storage, and visible canvas is not pixel verification. The original Round 4 heap field was not GC-controlled. The default JSON output is `out/perf/browser-profile.json`. Historical before was captured before Round 4 UI changes; after uses a corrected reply counter. Interpretation and deferred work are in `docs/perf-review.md`.
The script captures editor and preview geometry at animation frames, CDP main-isolate JS heap, and main-thread tasks over 50 ms. It measures chapter switching, typing the same text with Outline, Sources and Comments open, sparse and broad outline search, source filtering and paging, highlight expansion, citation and embed completion, and Word export. It checks the finished edits, search result counts, and the presence of a Word document part in the downloaded DOCX. Browser action timings include Playwright round trips. Each typing phase uses 12 text inputs with no added delay. One Chromium run per revision is observational. The main heap excludes workers and native backing storage. The default JSON output is `out/perf/browser-profile.json`. The original Round 4 heap field was not GC-controlled. Interpretation of the earlier runs is in `docs/perf-review.md`.
Loading