Skip to content

chore(frontend): add reproducible browser-memory benchmark script#13510

Open
AntonioVentilii wants to merge 5 commits into
mainfrom
claude/noisy-wallet-memory-plan-so0iz0-memory-benchmark
Open

chore(frontend): add reproducible browser-memory benchmark script#13510
AntonioVentilii wants to merge 5 commits into
mainfrom
claude/noisy-wallet-memory-plan-so0iz0-memory-benchmark

Conversation

@AntonioVentilii

Copy link
Copy Markdown
Collaborator

Motivation

The repo currently has no browser-memory measurement of any kind (no performance.memory usage, 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

  • Add scripts/perf.memory.mjs + npm run perf:memory (uses the existing @playwright/test dependency and a built-in static server — no new packages). It measures against the production build/:
    1. Landing page (logged out) — JS heap used/total, DOM nodes, JS transferred, renderer PSS.
    2. Worker scaling — spawns N copies of the real built wallet-worker bundle (the app spawns ~one per enabled ICRC/BTC/SOL token) and reports marginal MB/worker, with an empty-worker control run to separate the V8-isolate baseline from bundle parse/init cost.
  • --json flag for machine-readable output; PERF_MEMORY_CHROMIUM / PERF_MEMORY_WORKERS env overrides.
  • Document the flow in HACKING.md (new "Memory Benchmarking" section).

Tests

Ran against today's main production build (Linux, headless Chromium):

Landing page (logged out):
  JS heap used / total: 14.9 / 15.7 MB
  JS transferred:       6.6 MB (7 files)
Worker scaling:
  Real worker bundle:   12.8–14.3 MB/worker
  Empty worker control: 0.9–1.3 MB/worker
  → ~12 MB/worker attributable to parsing/initializing the 1.08 MB worker bundle

i.e. a 50-token user pays ~700 MB in workers alone — consistent with the ~1 GB field reports. eslint and prettier pass on the new files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GiZ8mmts9aZCCANKQfQ1Xi


Generated by Claude Code

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
Comment thread scripts/perf.memory.mjs Fixed
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
@AntonioVentilii AntonioVentilii marked this pull request as ready for review July 11, 2026 08:29
@AntonioVentilii AntonioVentilii requested a review from a team as a code owner July 11, 2026 08:29
Copilot AI review requested due to automatic review settings July 11, 2026 08:29
@zeropath-ai

zeropath-ai Bot commented Jul 11, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to 4576d7e.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► package.json
    Add perf:memory script for memory benchmarking
► scripts/perf.memory.mjs
    Add memory benchmarking tool script

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.mjs to benchmark landing-page metrics and worker-scaling memory costs (with Linux /proc PSS support).
  • Add perf:memory to package.json scripts.
  • 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.

Comment thread scripts/perf.memory.mjs Outdated
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 thread scripts/perf.memory.mjs
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
};
Comment thread scripts/perf.memory.mjs Outdated
for (const pid of readdirSync('/proc').filter((entry) => /^\d+$/.test(entry))) {
try {
const cmd = readFileSync(`/proc/${pid}/cmdline`, 'utf8');
if (cmd.includes('chrom')) {
Comment thread HACKING.md

## Memory Benchmarking

`npm run perf:memory` measures the browser-memory profile of the production build with a headless Chromium (via the already-installed Playwright):
AntonioVentilii and others added 2 commits July 11, 2026 08:36
- 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
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.

4 participants