Contribute
Performance
Português: docs/pt-BR/desempenho.md
Paprika must stay fast on a real workspace, not only on the demo. This page defines the worst case, the budgets the perf suite checks, and how to profile. The rules are in AGENTS.md rule 7; the work that brings each number inside its budget is section W of the backlog.
#Worst case
Measured on the maintainer's real workspace (14,752 nodes, 7.2 MB, main 17c9fac). The suite never uses that export (it is private): it builds a synthetic document with the same shape, in code (packages/e2e/test/perf/synthetic.ts, deterministic):
- about 15,000 nodes over 7 pages;
- one page with about 3,500 nodes (the heavy page, opened first), made of nested auto-layout frames with strokes, text, paths and ellipses;
- 1,000 component instances;
- several agents writing at the same time;
- one slow tab (a WebSocket consumer that stops reading).
#Budgets
The numbers live in one file, packages/e2e/test/perf/budgets.ts.
| Budget | Limit | Today | Ticket |
|---|---|---|---|
| WS bytes per one-prop write | 2 KB | 608 B (enforced; was 7.23 MB) | PAP-A-057 |
| Doc snapshots on open | 1 | 1 (enforced; was 2) | PAP-A-057 |
| Wire bytes of the snapshot on open, as % of its JSON | 25% | 9% on the worst case (enforced; was 100%: /ws had no permessage-deflate). The maintainer's real workspace (17,139 nodes) goes from 8.4 MB to 1.25 MB |
PAP-A-070 |
| Server time per one-prop write | 50 ms | 2 to 7 ms over a small document (enforced; was 1.08 s) on a plain node | PAP-A-060 |
| Server time per one-prop write on a component master with 1,000 instances | 50 ms | 0.29–0.34 s (report-only; was 0.35–0.42 s before the copies kept their place in the node map, and 2.2 s before that). The same write now sends 384 KB over /ws instead of the whole document (5.9 MB). What is left is rebuilding the 1,000 copies and writing their rows |
PAP-A-060 |
| Server time to create a frame with 200 children | 50 ms | 31 ms over a small document (report-only; was about 450 ms) | PAP-A-060 |
| Server time to delete a frame with 200 children | 50 ms | 14 ms over a small document (enforced; was about 430 ms) | PAP-A-060 |
| Script time in the tab on one incoming write | 50 ms | 7–26 ms over the small document in 11 runs on main 3502274 (enforced; was about 0.1 s on the old app and 2.5 s before that, when the inspector linted the whole document on the main thread for every version) |
PAP-A-068 |
| p95 frame on scroll, zoom and pan | 20 ms | met (17 ms; was 33–83 ms) | PAP-A-062 |
| Panel resize step | 20 ms | met (17 ms over the small document; was 750 ms) | PAP-A-063 |
| Time until an agent-created 200-node frame is visible, small document | 1 s | 180 ms (enforced; was a 200-step replay) | PAP-A-064 |
| Same, on the heavy page of the worst case | 1 s | 106–146 ms in 11 runs on main 3502274 (enforced; was 0.7–0.97 s on the old app and 25 s before that) |
PAP-A-068 |
| Slow tab ends on the latest version | always | no (481 of 485) | PAP-A-058 |
Count budgets (bytes, messages, snapshots, versions) are exact. Time budgets are relative: the suite measures the same action on a small document in the same run and the budget applies to the difference, so a slow or busy machine does not fail it. The agent-build times are the exception: they are a product limit, measured as is. Created nodes are never hidden while the agent outline walks them, so what is left on the heavy page is the tab rendering the write, not the walk.
Each budget starts report-only (enforce: false): when exceeded it prints known-failing with its ticket and the run still passes. The PR that meets a budget sets enforce: true; from then on an excess fails the suite. A feature that adds a hot path adds its scenario and its budget in the same PR.
#Running the suite
pnpm build
pnpm test:perfIt needs the web build (apps/web/dist/client) and Playwright Chromium for the browser scenarios (see development; PAPRIKA_CHROMIUM points at another Chrome). Without the web build only the server scenarios run. It prints a scenario | budget | measured | limit | status table and writes the same data as JSON to $PAPRIKA_PERF_REPORT (default report.json in a fresh paprika-perf-report-* directory under the OS temp directory; the path is printed). It is not part of pnpm check.
#The app (apps/web)
The browser block of packages/e2e/test/perf/perf.test.ts opens the app (/w/<doc> from apps/web/dist/client) on the worst case and on a small document in the same run, and applies the budgets above to the difference. It is skipped when there is no web build. Its scenarios:
pan-zoom: wheel pan and ctrl+wheel zoom on the heavy page, p95 frame (budgetframeP95Ms, enforced).panel-resize: five steps of dragging the firstseparatorof the workspace, measured to the second animation frame (panelResizeStepMs, enforced).alt-measure: with a visible node selected (Ctrl-click) andAltheld, the pointer steps onto up to 12 other visible nodes, each step measured to the second animation frame (altMeasureStepMs, enforced).tab-incoming-write: script time in the tab, from the CDP metrics, when another client writes one property (tabWriteScriptMs, enforced), together with the longest task and the number of long tasks. The same test checks that opening the page receives one snapshot (wsSnapshotsOnOpen).agent-build: time from an MCPcreate_nodesof a 200-node frame until all 200 elements are in the DOM and painted, on the small document and on the heavy page (agentNodeVisibleSmallMsenforced,agentNodeVisibleMsenforced).
The other scenarios in the file (ws-bytes, ws-open, server-write, slow-tab) exercise the server and the wire, not the app.
Also in the app:
- Commit counts in Vitest:
apps/web/src/perf/*.perf.test.tsxrender the editor and the overview in jsdom on a generated N-node document and assert how many times each region commits for an action (they run withpnpm --filter @paprika/web test). They check that an action does not re-render regions it should not touch. They are not time budgets and the timings they print are jsdom's, which say nothing about a browser. - A manual measure:
?perf=1on a development build (vite dev) turns onRegionProfiler(apps/web/src/perf), which records each region's commits andactualDurationand exposes them aswindow.__paprikaPerf(read it from the console or a script). It is off in a production build. Numbers taken this way are from a development build.
What is still missing, with no scenario and no budget in packages/e2e/test/perf (rule 7(b) of AGENTS.md): selecting a node and scrolling the layers panel on a page with thousands of nodes (jsdom only measures it today), dragging, resizing or rotating a selection on the heavy page, editing text, undo and redo, the time to open the heavy page (first paint), the WASM layer paint and the overview with many projects. A change to one of those hot paths adds its scenario and budget in the same PR. The Vitest commit tests are not that budget.
#How to profile
- Server: a Go test or benchmark with
go test -cpuprofile cpu.out, thengo tool pprof -top cpu.out; or time the MCP call against the worst case. Report the top functions before and after. - Canvas: drive the page with Playwright and read
Performance.getMetricsover CDP (ScriptDuration,LayoutDuration,RecalcStyleDuration) before and after the gesture, collectlongtaskentries with aPerformanceObserver, and record frame times withrequestAnimationFramedeltas during wheel pan, zoom, panel drag or an incoming write.packages/e2e/test/perf/helpers.tshas these helpers. - Put the numbers (before and after, worst case) in the PR description.