chore(frontend): add reproducible browser-memory benchmark script#13510
Open
AntonioVentilii wants to merge 5 commits into
Open
chore(frontend): add reproducible browser-memory benchmark script#13510AntonioVentilii wants to merge 5 commits into
AntonioVentilii wants to merge 5 commits into
Conversation
Adds npm run perf:memory, which serves the production build to a headless Chromium and reports (1) logged-out landing-page JS heap / DOM / transferred JS and (2) the marginal memory cost per wallet worker, measured by spawning N copies of the real built worker bundle with an empty-worker control run. The app spawns roughly one worker per enabled ICRC/BTC/SOL token, so the per-worker cost times the token count estimates steady-state usage — the scenario behind the ~1GB field reports. Measured today: ~13-14 MB per worker, of which ~12 MB is parse/init of the monolithic worker bundle. Uses the existing @playwright/test dependency; no new packages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiZ8mmts9aZCCANKQfQ1Xi
Addresses the CodeQL check-then-use finding: replace the stat-then-readFile sequence with a single readFile attempt per candidate (path, its index.html, SPA fallback) and reject request paths that resolve outside build/. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiZ8mmts9aZCCANKQfQ1Xi
|
✅ No security or compliance issues detected. Reviewed everything up to 4576d7e. Security Overview
Detected Code Changes
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a reproducible, Playwright-based benchmark to measure browser memory characteristics of the production frontend build (build/), with a convenient npm run perf:memory entrypoint and documentation so results can be re-run and tracked over time.
Changes:
- Introduce
scripts/perf.memory.mjsto benchmark landing-page metrics and worker-scaling memory costs (with Linux/procPSS support). - Add
perf:memorytopackage.jsonscripts. - Document the benchmarking workflow in
HACKING.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
scripts/perf.memory.mjs |
New benchmark script that serves build/ and records heap/DOM/network + worker-scaling memory metrics. |
package.json |
Adds npm run perf:memory script entry. |
HACKING.md |
Documents how to run the new memory benchmarking flow and interpret results. |
| import { extname, join, resolve, sep } from 'node:path'; | ||
|
|
||
| const BUILD_DIR = join(process.cwd(), 'build'); | ||
| const MAX_WORKERS = Number(process.env.PERF_MEMORY_WORKERS ?? 50); |
Comment on lines
+141
to
+151
| const { metrics } = await cdp.send('Performance.getMetrics'); | ||
| const metric = (name) => metrics.find(({ name: n }) => n === name)?.value ?? 0; | ||
|
|
||
| const result = { | ||
| jsHeapUsedMb: toMb(metric('JSHeapUsedSize') / 1024), | ||
| jsHeapTotalMb: toMb(metric('JSHeapTotalSize') / 1024), | ||
| domNodes: metric('Nodes'), | ||
| jsTransferredMb: toMb(jsTransferred / 1024), | ||
| jsFiles, | ||
| rendererPssMb: rendererPssKb() !== undefined ? toMb(rendererPssKb()) : undefined | ||
| }; |
| for (const pid of readdirSync('/proc').filter((entry) => /^\d+$/.test(entry))) { | ||
| try { | ||
| const cmd = readFileSync(`/proc/${pid}/cmdline`, 'utf8'); | ||
| if (cmd.includes('chrom')) { |
|
|
||
| ## Memory Benchmarking | ||
|
|
||
| `npm run perf:memory` measures the browser-memory profile of the production build with a headless Chromium (via the already-installed Playwright): |
- scope the /proc PSS scan to this script's own process tree so unrelated Chrome instances on the machine are excluded from the numbers - read the renderer PSS once when building the landing result - clamp PERF_MEMORY_WORKERS to a positive integer with a 50 fallback - document the playwright:install prerequisite in HACKING.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiZ8mmts9aZCCANKQfQ1Xi
…' of https://github.com/dfinity/oisy-wallet into claude/noisy-wallet-memory-plan-so0iz0-memory-benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The repo currently has no browser-memory measurement of any kind (no
performance.memoryusage, no heap tooling — only the reactivity-recomputation counter and the bundle-size CI diff). Meanwhile users report OISY using 1 GB+ of browser memory. The investigation of that report needed a repeatable measurement, and this script is that measurement, productionized so the numbers can be re-run by anyone and tracked release-over-release instead of living in one-off DevTools sessions.Changes
scripts/perf.memory.mjs+npm run perf:memory(uses the existing@playwright/testdependency and a built-in static server — no new packages). It measures against the productionbuild/:--jsonflag for machine-readable output;PERF_MEMORY_CHROMIUM/PERF_MEMORY_WORKERSenv overrides.HACKING.md(new "Memory Benchmarking" section).Tests
Ran against today's
mainproduction build (Linux, headless Chromium):i.e. a 50-token user pays ~700 MB in workers alone — consistent with the ~1 GB field reports.
eslintandprettierpass on the new files.🤖 Generated with Claude Code
https://claude.ai/code/session_01GiZ8mmts9aZCCANKQfQ1Xi
Generated by Claude Code