[turbopack] On-demand memory report for the dev server#96086
Draft
lukesandberg wants to merge 4 commits into
Draft
[turbopack] On-demand memory report for the dev server#96086lukesandberg wants to merge 4 commits into
lukesandberg wants to merge 4 commits into
Conversation
lint audit telemetry lints
3 tasks
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.

What?
Adds an on-demand memory report for the Turbopack dev server. While
next devis running you can ask the backend what it is holding in memory, without restarting or attaching an external profiler:GET /__nextjs_turbopack-memory?format=json|markdownnext internal turbopack-memory [--format json|markdown] [--url <devServerUrl>]The report enumerates every cell of every task and groups it by value type, ranked by
strong_count— the number of livetriomphe::Arcreferences to the cell's data, a cheap and real proxy for retention. It is split into two sections:The JSON is additionally augmented with Node process stats (RSS, heap, pid, uptime) by the dev-server layer.
Why?
We needed a way to diagnose what Turbopack retains after eviction on a live dev server.
This supersedes #90271, which is the original attempt at this feature. That PR estimated per-item memory via bincode encode-and-discard, which both over- and under-counts badly (it ignores reference-counted structures like
RcStr/Ropeand doesn't account for hash-table slack). It was also ~2000 commits behindcanaryand predated the backend refactor. This PR keeps that PR's delivery mechanism (NAPI binding → HTTP endpoint → CLI, JSON + markdown) but drops the size estimation entirely in favor of the strong-count / transient-vs-persistent breakdown, which is derived from the existingStorage::audit_all_cellsinstrumentation on this branch. #90271 is being closed in favor of this one.How?
turbo-tasks-backend):TurboTasksBackend::collect_memory_report()builds a structuredMemoryReport { transient, persistent }fromaudit_all_cells(), reusingdebug_trace_transient_taskfor the transient sample chains. The previous behavior — dumping a text report to/tmpon every eviction cycle — has been removed; the report is now on-demand only.project_get_memory_reportexposes it asprojectGetMemoryReport(runs on a blocking thread since it walks all tasks).getMemoryReportMiddlewareserves the endpoint and renders the markdown; wired into the Turbopack hot-reloader middleware chain.next internal turbopack-memorydiscovers the running dev server from the.nextlock file (or--url) and prints the report.1423registered for the failure path.This is a dev-only diagnostic tool, so no telemetry is added.
Closes PACK-6917
Supersedes #90271