Skip to content

docs: add a section on measuring memory at runtime - #98291

Open
xabierlameiro wants to merge 3 commits into
vercel:canaryfrom
xabierlameiro:docs/measure-memory-at-runtime
Open

docs: add a section on measuring memory at runtime#98291
xabierlameiro wants to merge 3 commits into
vercel:canaryfrom
xabierlameiro:docs/measure-memory-at-runtime

Conversation

@xabierlameiro

Copy link
Copy Markdown

Improving Documentation

  • Ran prettier with the repo config on the changed file; no changes.
  • Read the Docs Contribution Guide.

What this adds

The memory guide covers next dev and next build: dependency count, Webpack
options, --experimental-debug-memory-usage, heap profiles and snapshots. It
says nothing about measuring a production server that grows over hours, which
is the case most memory issues in the tracker describe.

This adds a short section, "Measure memory at runtime", after "Analyze a
snapshot of the heap". It lists the four things that make a runtime measurement
reliable (sample from a warm process, force a GC before every sample, watch
rss and arrayBuffers as well as heapUsed, measure one route per fresh
process) and explains what a snapshot diff between an early and a late sample
gives you.

Why the method matters

Forcing a GC before each sample is what separates retention from garbage that
hasn't been collected yet, and it's also what makes some real leaks look fine
if you only watch heapUsed: part of the retention lives outside the V8 heap.
Without warm-up, the first requests to a route (compilation, caches) read as
growth. Without one route per process, growth can't be attributed. These are
the mistakes I made before I got a reliable measurement, and none of them are
written down in the guide today.

External tools

The last paragraph names memlab and next-leak as tools that automate this
loop. They're external, the same way the Chrome DevTools link already in this
guide is. I wrote next-leak; if naming it is a problem, I'm happy to drop that
paragraph, the method stands on its own.

xabierlameiro and others added 3 commits September 5, 2026 15:16
The memory guide covers next dev and next build only. This adds the
four rules that make a runtime measurement reliable (warm process,
forced GC before each sample, rss and arrayBuffers, one route per
process) and points to memlab and next-leak, external tools of the
same kind as the Chrome DevTools link already in the guide.
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.

1 participant