Skip to content

bench(nad): reproducible benchmarks for the adaptive-zoom writer perf work#11

Draft
gautierbureau wants to merge 1 commit into
integration/nad_create_svg_adaptive_zoomfrom
claude/perf-nad-benchmarks
Draft

bench(nad): reproducible benchmarks for the adaptive-zoom writer perf work#11
gautierbureau wants to merge 1 commit into
integration/nad_create_svg_adaptive_zoomfrom
claude/perf-nad-benchmarks

Conversation

@gautierbureau

Copy link
Copy Markdown
Owner

What

A benchmarks/ suite that measures — reproducibly — the three performance PRs stacked on integration/nad_create_svg_adaptive_zoom (powsybl#423). Additive only; no product code changes. Companion to #7 (metadata indexing), #8 (geometry precision) and #9 (lazyMount); the numbers in those PR descriptions come from this suite.

Benchmarks

script measures needs
nad-metadata-index-bench.mjs writer metadata-lookup cost: find/filter vs Map index node only
nad-geometry-precision-bench.mjs emitted coordinate-text size at precision 0–3 node only
nad-lazy-mount-bench.mjs eager vs lazy off-screen viewer construction real headless Chromium + demo server + playwright-core

The two node benches are self-contained (the compared implementations are inlined and mirror the shipped code, which is covered byte-for-byte by unit tests). The lazy-mount bench drives the real viewer via the demo server (Vite /@fs), and can exercise either the raw-SVG-injection or the powsybl#423 client-writer construction path (CREATE_SVG_FROM_METADATA=1).

node benchmarks/nad-metadata-index-bench.mjs
node benchmarks/nad-geometry-precision-bench.mjs
npm install --no-save playwright-core && npm run start &
node benchmarks/nad-lazy-mount-bench.mjs        # N=8, raw-SVG path
N=16 node benchmarks/nad-lazy-mount-bench.mjs
CREATE_SVG_FROM_METADATA=1 node benchmarks/nad-lazy-mount-bench.mjs

Recorded results (headless Chromium, dev mode)

Absolute times are machine/run-dependent; the ratios are the portable figures.

Metadata indexing — writer access pattern, find/filter vs Map index:

diagram old indexed speedup
N=1000 24.1 ms 0.49 ms 50×
N=4000 325.7 ms 2.73 ms 119×
pegase 33.2 ms 0.31 ms ~100×

Old ~quadruples per doubling of N (O(n²)); indexed grows ~linearly.

Geometry precision — coordinate-text bytes on real pegase geometry:

precision raw gzip vs p2 (gzip)
2 (default) 57.1 KB 10.4 KB
1 49.4 KB 8.7 KB −16.5%
0 34.0 KB 6.6 KB −36.2%

(The whole-document figures measured by the writer's own size test — 168.5 KB gzip → 156.0 / 140.8 KB — are in #8; smaller percentages there because coordinates are only part of the SVG.)

Lazy off-screen construction — real browser, N viewers stacked in one viewport:

path N per-viewer eager lazy on load saved ratio
raw SVG inject 8 ~41 ms 326 ms 81 ms (2 built) ~244 ms 4.0×
raw SVG inject 16 ~41 ms 658 ms 82 ms (2 built) ~575 ms 8.0×
powsybl#423 client writer 8 ~373 ms 2985 ms 746 ms (2 built) ~2.2 s 4.0×

Ratio ≈ N / visible, so a page showing ~1 of N approaches an N× reduction; all N build on demand while scrolling. The client-writer path costs ~9× more per viewer than raw injection — which is exactly where the metadata indexing (#7) pays off.

Notes

Draft; base is the in-progress adaptive-zoom branch. playwright-core and (for the writer's own size test referenced above) fast-xml-parser are dev-only and installed --no-save — not added to package.json here.

🤖 Generated with Claude Code


Generated by Claude Code

…perf work

Add a benchmarks/ suite measuring the three performance changes stacked on the
adaptive-zoom SVG-writer branch:

- nad-metadata-index-bench.mjs: replays the writer's per-element metadata
  access pattern with linear scans vs Map indices (self-contained; the indexed
  functions mirror metadata-utils.ts). Shows O(n^2) -> O(n): pegase 33ms -> 0.3ms.
- nad-geometry-precision-bench.mjs: coordinate-text size at precision 0-3 on
  real pegase geometry, raw and gzipped.
- nad-lazy-mount-bench.mjs: real headless-Chromium eager vs lazy off-screen
  viewer construction; N/visible-x fewer constructions on load (4x at N=8),
  saving ~2.2s on an 8-viewer page via the client-writer path.

README.md documents how to run each and records the measured numbers, noting
that absolute times are machine-dependent while the ratios are portable.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T1fMV9gtgHLBKoSAShYSdA
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.

2 participants