Skip to main content

Snapshot Ladders

A single snapshot can't tell you whether memory grows. For that, the growth tools work on a ladder: an ordered series of snapshots (rungs) taken while one interaction repeats, for example a snapshot after every few times a dialog opens and closes.

Most ladder tools load each rung only for as long as they need it, so a long ladder doesn't have to fit in memory at once.

Give the Server a Ladder​

A ladder can be given in three ways:

  • paths: an ordered list of snapshot files. If the files are named rung_NN_cNNN.heapsnapshot, the number of repetitions (cycles) at each rung is read from the name. Otherwise the rungs are taken to be evenly spaced, and the report says so.
  • run_dir: a directory whose run.json lists the rungs, the cycles driven at each one, and optionally a settle rung, taken after the page was idle and garbage-collected. The settle rung is what tells a leak apart from work that is still in progress. memlab_leak_report, memlab_settle_check, memlab_detached_dom and memlab_pending_promises read it by default (include_settle: false skips it): it is a final column, and every row that grew reads HELD (more than a tenth of its growth is still there) or DRAINED (it went away, so it was work in flight, not a leak). A drained row never reads as a STEP or LINEAR leak, and when a detached-DOM ladder's whole growth is gone at settle the analysis battery says so above its digest.
  • ladder:<name>: a name registered once with memlab_ladder.

With run_dir, rungs picks rungs without guessing file names (which carry cycle counts you cannot predict). Each entry is an index (negative counts from the end), a cycle count such as "c50", "first", "last", "settle" ("settle_off" / "settle_on" for one arm of an A/B round, where a bare "settle" is ambiguous), or a rung file name. A tool that reads a run but has no rungs of its own reads the picked rungs as paths; a tool that reads one snapshot takes one rung. A selector that names no rung, and a snapshot path that does not exist, are answered with the rungs that do exist and the closest one, for example Closest: rung_01_c25.heapsnapshot. In …/run.json, rung_01_c25 is rung 1 (or "c25").

A rung run.json lists whose file (plain or .gz) is gone, as after a prune that kept only the first, last and settle rungs, is left out of a run_dir ladder: the tools read the rungs left, and memlab_verdict_table / memlab_validate_finding say which rungs are gone (two driven rungs read Shape unknown).

Find What Grows​

Start With the Verdict Table​

memlab_verdict_table({run_dir}) (or paths, oldest first, with the settle rung among them) gives one row per candidate population: the top growing classes (V8 engine classes left out), collections, detached DOM element types, pending-promise chains and listener groups (top of each kind by growth, 20 by default, then up to half as many more per kind whose Shape is a leak candidate: linear, a last-interval Δ above 0 and kept at settle, so a small population that grows steadily is not crowded out by large one-time steps; a line under the table counts the growing rows that were cut). Each row has its count at every rung and at settle, the growth Shape, the last-interval Δ, the settle residual (settle minus the first rung, with the share of the growth kept), the owner on the production path once every development-only edge is cut (or dev-only when no such path exists), the artifact class, and the known family with its verdict. The Validate column is the leak gate: PASS only when the Shape is linear with a non-zero last-interval Δ that is kept at settle, the row has a production owner, no artifact class, no known family that is bounded, transient or development-only, and (for a class row) it is not an aggregate engine class such as system / PropertyArray, a string class or Object, whose growth sums many unrelated owners. Every other row reads FAIL <class>: <first reason>, where the class is what to report it as: one-time, transient, bounded, dev, flat, aggregate, artifact or unknown. A row is a leak candidate (yes) exactly when it passes. The Bound column is memlab_bound_evidence on the row's example node, read only for the rows that pass the rest of the gate: a bound fails the gate. The same rows are in structuredContent.rows, with the gate's verdict, class and every failed check under validate, and the bound evidence under bound.

KindKeyPer rung (→ settle)ShapeLast-interval ΔSettle residualProduction owner (dev cut)Known familyCandidateValidate
classLeakItem0 → 40 → 80 → 120 → 120linear+40+120 (100% kept)Object.leaks → Array.119—yesPASS
classStepItem0 → 200 → 200 → 200 → 200step→flat0+200 (100% kept)Object.steps → Array.199——FAIL one-time: Shape step→flat (+1)
classTracedItem0 → 25 → 50 → 75 → 75linear+25+75 (100% kept)Object.traced → Array.74known: traced items, time-bounded—FAIL bounded: known family traced items

To gate one population that is not in the table (any growth), pass it to memlab_validate_finding with the same ladder: key (a Key the table prints, a class name or collection label; an exact match first, else a case-blind substring), population: "<kind>:<key>", node_ids from one rung (each rung then counts how many of those ids it holds), or the name of a population saved with save_as (see Save a Population Once). It prints every check with its reading and either PASS or the class to report the population as. A key that matches several populations (as a substring, or one name in two kinds) is not a PASS: when any of them passes, the verdict is AMBIGUOUS until population: "<kind>:<key>" names one. When the exact match did not grow (a class with one instance) and populations containing the key did, those growing ones (up to 5) are gated beside it, so the answer is AMBIGUOUS or FAIL with every row shown, never the flat match's FAIL alone; memlab_counterevidence lists them the same way. One class split by node type is one population and PASSes when any of its rows does. Write "production leak" or "unbounded" only for a PASS; in a draft, not_problem: FAIL <class>: <reason> closes the lead for memlab_coverage_check.

Then confirm each yes row with the tools below, and give every other row its one-line reason from its columns.

Is It Bounded?​

memlab_bound_evidence({node_id}) (or key, a collection Key the table prints) looks at the collection a node is, or is held by, for the two bounds a heap shows. One is a pending timer (a Node.js Timeout, a scheduler task record or a browser timer) whose callback holds one of the collection's keys or values in its own scope: a per-entry expiry or cleanup, bounded-by-time, with the delay. A timer that only sees the collection, such as a top-level poller, is listed but not counted. The other is a cap next to it: a max…, limit or capacity field on its owner object at or above its current size, a closure-scope constant whose name shares a word with the name the scope holds the collection under (MAX_CACHE_SIZE for cache; any other constant of an enclosing scope is only listed), or an LRU shape (a Map plus a linked list), bounded-by-cap. A cap in characters or bytes (maxRetainedLogChars) is reported in its unit and not compared with the entry count; a duration (…Ms, ttl, timeout) is not a cap. Otherwise it answers no-bound-found, or numbers not captured when the snapshot was taken without numeric values (see Capture Numbers), because a cap and a delay are numbers. Each answer lists its evidence; read the timer or the cap check in the source before citing it.

What Argues Against It?​

memlab_counterevidence takes the same population and ladder as memlab_validate_finding (key, population or node_ids, with run_dir or paths) and lists the reasons a leak claim on it would be wrong, strongest first:

  • strong: it drains at settle; a plateau (step→flat, late-step) or no growth; a last-interval Δ of 0; a known family that is bounded, transient or development-only; development-only after the dev cut; bound evidence (a cleanup timer, a cap, an LRU); an aggregate engine class or an artifact class.
  • medium: less than half of the growth kept at settle; growth slowing (the last interval adds less than half the first interval's rate, the way a fill nears its plateau); no settle rung; no owner read; a Shape of unknown; fewer than three driven rungs.
  • weak: production only beside a shorter development path; a capture without numbers, so a cap or a timer delay cannot be ruled out.

When nothing argues against the claim it says No counterevidence found and lists what it checked. Run it on every row you are about to call a production leak, and quote its strongest reason for each row you call not a leak.

Check the Report​

memlab_report_lint({path: "REPORT.md", run_dir}) (or paths / handles) reads a written report's claims: a population named in backticks (a class or a collection key, as the verdict table prints it), or a dotted name such as Logger.logs written without them when a verdict row has that name, with a classification on the same line, or under a heading that names it: "production leak", "unbounded", "dev-only", "bounded" (also "plateau", "one-time", "capped"), "transient" or "not a leak". It recomputes each population with the leak gate on the ladder and prints one row per claim: what the report says, what the ladder says (the series, Shape, last-interval Δ, owner after the dev cut and the gate), and OK, CONTRADICTION or "not on the ladder". Lines that state a classification but name no population are listed as not checked, and a report with no named claim at all reads NOTHING WAS CHECKED, not a clean result. The contradictions it flags:

  • "unbounded" with a last-interval Δ of 0, or a Shape other than linear;
  • "production leak" or "unbounded" when the gate FAILs, or when no path survives the dev cut;
  • "dev-only" when a production path survives the dev cut;
  • "bounded", "transient" or "not a leak" when the gate PASSes, and "transient" when most of the growth is still there at settle.

Run it as the last step before filing a ladder report, and fix every CONTRADICTION row (or name the evidence that overturns the gate).

A Ladder Investigation​

A typical ladder investigation, in conversation:

  1. Find what grows: "Which classes and shapes grow every cycle?" (memlab_leak_report, memlab_shape_census_diff, memlab_collection_diff)
  2. Tell a leak from a working set or a backlog: "Does this growth level off, and does the settle rung give it back?" (memlab_rate_model, memlab_settle_check, memlab_retention_windows)
  3. Find the owner: "Who holds the newest instances?" (memlab_cohort_owners, memlab_growth_cohort, memlab_trace_all, memlab_react_owners)
  4. Size the fix: "How many bytes come back if this property is cleared?" (memlab_field_release_impact, memlab_what_if)
  5. Verify the fix: "Compare the ladders from before and after the fix." (memlab_verify_fix, memlab_replicate)

Reading the Numbers explains how memlab_leak_report tells warm-up and one-time growth from a leak.

memlab_cohort_owners({run_dir}) takes the top growers from the first rung to the settle rung and, for each, the 400 newest instances (n): each is mapped to its owner (the nearest dominator with a class name) and the owners are tallied by their shortest-path label (module:<Name>.<export>, global:<name>), with the owners' retained size. An owner that is the measurement harness (harness:<name>) or a development-only module is marked. A row is dev-only when every owner under its label is held only by development roots; when only some are, it says how many (1 of 5 owners dev-held) and still counts as the app's. The leak report's Top retainer column is the top row of the same tally over each class's 200 newest instances (within a 15-second budget for the report), so a large static collection no longer wins it over the one that grew.

memlab_collection_diff({run_dir}) also reads the settle rung run.json names (include_settle: false leaves it out), so each row's Shape says whether its growth survived settle. Its linear rows are candidates by Shape only: caps, timers, owners and known families are read by the leak gate (memlab_validate_finding, or memlab_verdict_table for every row).

memlab_collection_diff adds a Keys column from the last rung: the newest keys of each growing collection, flagged UNIQUE KEYS when they look new per request (URLs with a query string, ids, timestamps, or keys that differ only in a number, such as a request counter), or APPEND LOG for an array of timestamped records of one shape. A memo keyed that way never hits twice for one key, so it grows until it is bounded or its keys are normalized. An append log is named apart: it needs a cap on its records, since its keys are only positions. Rows whose Shape is linear are listed first; the table prints each row's Shape and last-interval Δ.

memlab_growth_atlas({run_dir}) writes every growing cluster of a round to one file, analysis/growth_atlas.md, as a background job. It runs the same per-class trend pass as memlab_leak_report, places each growing class at the retainer path most of its last-rung instances share, and merges the classes on one normalized path into a cluster. Each cluster lists its bytes per cycle, its classes, the source module, the finding-index verdict and a ready memlab_retainer_trace call. The reply is the top 10 clusters and the file's path.

memlab_leak_report ends with Specialist next calls: for each growing family it names the tool built for it, with the arguments filled in for this ladder. Native EventListener rows go to memlab_duplicate_subscriptions, Detached … rows to memlab_detached_dom and memlab_island_doors, Promise rows to memlab_pending_promises, timers and scheduler tasks to memlab_timers, React update records to memlab_react_update_queues, Map/Set/Array rows to memlab_collection_diff, animations and DOM observers to memlab_observer_census, and bound functions to memlab_bound_functions. memlab_round_digest({format: "doc_markdown"}) puts the same calls on its Next line.

Run Several Analyses at Once​

memlab_analysis_battery runs a set of ladder analyses over the same rungs, and writes a digest of their results. It keeps rungs parsed between its steps while memory allows (MEMLAB_RETAIN_RUNGS caps how many).

Outside a battery, the server keeps rungs parsed between calls. How many follows free memory: the rungs it holds plus as many more of their typical parsed size as fit in both the machine's free memory and the JS heap's headroom (2 to 16; 6 before the first rung is parsed). MEMLAB_SESSION_RUNGS fixes the number instead. A rung is kept only while the next parse still fits in memory (MEMLAB_SESSION_RUNG_HEADROOM). The ladder tools read the rungs already parsed first, so a repeat call over a ladder longer than the cache still reuses every cached rung. A rung is parsed once even when several calls need it at the same time (background jobs over one ladder): the later calls wait for the first parse and read its graph. Each result that read rungs ends with a line that says what the call cost and why:

rungs: 3 cached / 1 parsed · re-parsed 1 evicted rung(s) (21s): batch per-rung work in one call (`memlab_batch`, the battery) or raise MEMLAB_SESSION_RUNGS · server RSS 5.1 GB (peak 7.9 GB) · 4 resident (rung cache 3/9 auto) · evicted rung_00.heapsnapshot (memory)
  • re-parsed counts the rungs this call parsed again because an earlier call's rung had been evicted, and what those parses cost. Ask several questions of a ladder in one call to avoid it.
  • resident counts every snapshot in memory; the rung cache part is the cached rungs against the cap (auto when it follows free memory).
  • evicted lists the snapshots dropped while the call ran, with the reason: cap (the cache was full), memory (no room for the next parse), idle (the idle unloader), rss-cap (MEMLAB_RSS_SOFT_CAP_MB) or load-headroom (a load needed the room).
  • A call stopped by the time limit ends with the same memory part.

Follow a Battery's Progress​

  • After each step, the battery rewrites battery.partial.json with the results so far, so you can read the first ones while a slow step runs.
  • Beside each tool's <tool>.txt it writes <tool>.json, a small summary for a program: {version, tool, stem, status, verdict?, headline?, table, columns, rows, rows_total, structured?}. rows are the first 20 rows of the tool's main table (cells cut to 200 characters), table the heading of the section it is in (or null), verdict a labelled verdict such as Verdict: **LEAK**, headline its first finding line, and structured the tool's own structured result when it is small; each file stays under 24 KB. memlab_round_digest({run_dir, format: "json"}) merges them with the audit verdict and the ladder into one JSON object, so a script reads a round's findings without scraping its reports. A step that is skipped or whose summary cannot be written has no <tool>.json, even if an earlier battery left one. When sidecars sit both in analysis/ and beside the manifest, the digest reads only the directory written last (sidecar_dir) and lists the other in older_sidecar_dirs, so an earlier battery's verdicts are not reported as this one's.
  • It writes battery.done.json to its output directory last, so a script can wait for that one file. Its timings array has every step's elapsed_ms, output chars and status (ok, error or skipped), and the report names the three slowest steps, so a slow battery shows what to leave out.
  • From the assistant, memlab_battery_status({battery_id, wait_ms}) waits for it.
  • With async: true, the battery runs in a separate copy of the server by default (isolate), so the server keeps answering other calls.
  • wait_for_rungs: "all" holds a battery until the round's round.done marker appears.

What Every Battery Measures​

Besides its analyses, every battery counts populations that grow outside the JavaScript heap, where analyses ranked by size don't notice them:

  • User content: files, blobs, blob_urls, abort_controllers and media_handles per rung. A discarded attachment that stays reachable adds one per attempt, while its bytes sit outside the heap.
  • Native browser objects: memlab_blink_native_census counts native (Blink) objects per rung and rates a fixed list of browser holders that have no cap, such as performance entries, User Timing marks, style caches and observer registrations. It is left out on A/B rounds.
  • Native memory pinned by JavaScript: memlab_native_pin_cost charges each native (browser) object to its nearest JavaScript dominator and groups them by that object: a promise by its first .then handler, a closure by its function. No heap total includes these bytes, so a promise that never settles while pinning browser objects through its reactions shows here. memlab_ab_compare reports the total per arm.
  • Broken UI text: memlab_rendered_text_audit reads the text React rendered, from the fibers, and flags [object Object], undefined, Invalid Date, a dropped parameter (You added & ) or an unreplaced {name} placeholder, by component. It sees rows a screenshot cannot, below the fold included.
  • Retained errors: memlab_retained_errors groups retained Error objects and error text by message template, on the first and last rung. It gives the change per cycle, marks templates that are new, and says when only an attached DevTools console holds a template. Errors are too small for any size-ranked analysis to show, but a template that grows every cycle is an error raised per interaction, which is often a visible bug.
  • Workers: when the round recorded performance.measureUserAgentSpecificMemory() per rung (the page must be cross-origin isolated), the digest gives its first and last value, with the dedicated workers' share. Workers and WebAssembly are in no page snapshot, so this is the only place their growth shows. Without it, the digest gives the workers' JS heap size read over the DevTools protocol instead.

Once per sweep (the round directories that share a parent), a standard battery also scans the final rung for sparse element stores, duplicated strings and duplicated objects: on the first round, and again when a round's final rung is at least 25% larger than any scanned so far.

Read the Digest​

  • The digest ends with the next calls worth making for that round. A call already suggested for the same class in an earlier round of the sweep is only named, not repeated.

  • memlab_round_audit checks the round itself. A check that an earlier round of the sweep showed word for word is folded into one "N check(s) unchanged since …" line; the verdict always shows. A round that is not TRUSTWORTHY lists every blocking check (or, when nothing blocks, every caveat) with its detail on the lines right under the verdict, in the audit, the battery digest and memlab_round_digest alike, and a blocking reason is never folded. The audit also names each recorded fix whose fixed_behind flag the build doesn't serve, because that round ran without the fix.

  • The audit verdict is about the round, not the sweep. An environment caveat the previous round already had (the same unserved-flag list, a warm isolate) is marked "unchanged since rN" and doesn't make the round CAVEATED. In an A/B round, the reload between the two arms is expected: each arm must be continuous and have at least 2 rungs.

  • Caveats about the app preset's flags on this build (a flag defined but read by no served code, absent from the registry, inert, or skipped as dead) are printed in full in the first round of a sweep that records them. Later rounds name them by id on one line, so a sweep's log does not repeat them every round. Re-auditing the first round prints them again.

  • A round run under a request-failing fault (codeload-fail, xhr-fail) is UNTRUSTWORTHY when the fault matched 0 requests: the app never requested what the pattern names, so the round ran unfaulted.

  • A runner that reloads the page on purpose at the start of a fault window, so the window loads code cold, records it in run.json faults.cold_start: {at_cycle, after_rung} along with the split in ladder_splits_after_rung. The audit accepts that one split (a caveat when a side has fewer than 2 rungs), and the ladder tools read each side as its own segment.

  • A runner that traces request lifecycles records run.json network_trace: {patterns: [{glob, media, requests, finished, failed, failure_rate, errors}]}. When at least half of the finished requests of a media: true glob failed (20 or more finished), the audit adds the caveat "≥50% of media requests failed (environment)": the round drove the media failure and retry path, so growth that follows the failures is not evidence about the working path. Otherwise it lists the traced globs as an info row.

  • A families file can also describe its app and the rows it explains, so a ladder handed over as bare snapshots (no run.json) gets it too. Put families.<app>.json files in a directory named by MEMLAB_FAMILIES_DIR. A file with "app": {"name": "…", "match": {"global": "<regex>"}} applies to a snapshot when the regex matches one of its global object names (Window / https://…). A family's "keys" (regexes) and "verdict" annotate every ladder and census table row whose key, closure or retainer label matches (eval_across growth, collection_diff, sweep, leak_report, census_diff, detached_dom, pending_promises) with a Known family column such as known: trace buffer, time-bounded (30-min cleanup). The column appears only when a row matches. The verdict is recorded history, not proof: a known row is a leak candidate only if its own Shape says so. findings.<workstream>.json files in the same directory are layered under the memlab_finding_index index: they answer check and list, an index entry wins on the same fingerprint, and a seed entry is written to the index only once a call changes it.

    {
    "app": {"name": "Chat", "match": {"global": "^Window\\b.*https?://chat\\.example\\.com"}},
    "families": [
    {"id": "trace-buffer", "label": "trace buffer", "keys": ["\\btracedItems\\b"],
    "kind": "bounded_window", "verdict": "time-bounded (30-min cleanup)"}
    ]
    }
  • A structure found once to be dev-only or capped (a profiler list, a trace buffer) can be registered in the round's families file with "kind": "dev_only" or "bounded_window" and a "locator" (the stable key helpers.stableKey prints). memlab_leak_report, memlab_artifact_budget and memlab_settle_check then subtract what it retains before computing rates, and say how much they took out.

  • memlab_hypothesis({run_dir, predicates, watch: true}) keeps predicates for the rest of the sweep. Every later battery checks them again and names any whose PASS or FAIL changed since the previous round. unwatch: [label] drops one.

  • memlab_hypothesis_sweep({run_dir}) runs a fixed library of named probes on the settle rung: pending promises, their reactions and chains (and the deepest chain), stale React context reads and the bytes only they retain, deleted Map/Set slots and the largest Map/Set, listeners across event registries and on the busiest event, and detached elements. It compares each value with the previous round of the same combo (same app and combo list, started earlier) and flags any that rose by more than 10%. When the two rounds ran a different kind of build, browser or served code (from run.json), it says so and flags nothing. The values are kept per app and combo under MEMLAB_STATE_DIR, so the previous round can be in another sweep directory, and written to the round's analysis/hypothesis_sweep.json. A probe that failed in the previous round is compared with the latest round before it where it ran (that round is named beside the value, as <sweep dir>/<round> when two recorded rounds share a name, and its build, browser and served code are checked too). An unreadable values file is reported and left alone: the round is not recorded over it. Servers recording at once take turns on a lock, so neither drops the other's round.

A/B Rounds​

When a round compares two arms (its run.json has an ab section and the ladder splits between them), the battery runs each step once per arm, writes <tool>.off.txt and <tool>.on.txt, and adds a memlab_ab_compare verdict table. The table always has rows for React state-update records (what a fix for setState calls that change nothing removes), and for files, blobs and blob_urls.

Each arm starts on a freshly loaded page, so memlab_ab_compare leaves out each arm's first interval by default (skip_intervals) when the round shows that page load still settling in any arm: a new isolate at the arm's second rung, a post-GC heap step of more than 5% (or one against every later interval), or an arm of 4 or more rungs. It then skips one rung in every arm that keeps at least two after it, so the arms are fitted over matching windows, and the header says per arm what it left out and why, for example "OFF: left out c0→c25 (post-GC 259.8 → 241.4 MB, −7.1%: the page load before the arm was still settling)". The table prints the rate over all rungs beside the steady one, and when leaving out that warm-up changes the verdict, the verdict says so.

Outside the battery, the ladder tools that take segment (memlab_leak_report, memlab_growth_atlas, memlab_collection_diff, memlab_shape_census_diff, memlab_react_update_queues, memlab_event_registry, memlab_census_diff and memlab_detached_dom) default to segment: "each" on an A/B round: called with only run_dir, they run once per arm and print an OFF arm and an ON arm section, each over its own rungs, instead of asking for a segment. segment: <n> still runs one arm, and on a round that reloaded mid-ladder without arms, segment: "each" gives one section per segment. A section with one rung is skipped ("nothing to compare"). The call returns an error when no section produced an analysis: every section with two or more rungs failed, or none had two. With format: "json" the call returns one JSON object, {tool, ab, sections: [{label, segment, rungs, result | error | skipped}]}, where result is that section's own JSON.

To measure your own probes on both arms, call memlab_ladder_probe once with segment: "all". On an A/B round it measures every arm in one pass, fits each on its own, and returns the memlab_ab_compare table. One call replaces a call per segment plus an ab_compare call, three passes over the same rungs.

Growth Outside the JavaScript Heap​

Some leaks are invisible in every heap figure. These tools find them:

  • memlab_hunt_report lists off-heap numbers per rung, with the browser process's memory beside the renderer's when the run recorded it, and flags growth that outpaces the JS heap. Live object URLs, for example, keep their Blob bytes in the browser process.
  • memlab_object_urls counts blob: URLs that were never revoked. When the run traced URL.createObjectURL, it also ranks the calling code by growth and prints the stack of the fastest-growing caller. It parses only the last rung, for the edges that hold the URLs, and counts the other rungs from their sidecar index; detail: "all" parses every rung.
  • memlab_pending_promises shows the native memory behind promises that never settle. Chrome keeps task-attribution state for every .then reaction, about 1 KB each, which no JavaScript retainer path shows. group_by: "chain" collapses pending promises linked because one settles when another does (a .then's derived promise, or a promise resolved with another promise) into chains: per chain, the root promise's owner path, the head's first .then handler, the depth at every rung and at settle, and the retained size. The root is the far end of the longest path from the head (at a fork, the deeper branch; ties go to the older promise), so a chain keeps the same root, and row, from rung to rung. A chain whose depth, or whose reaction-chain length at a flat depth, grows every rung and survives settle is flagged: it is the recursive step().then(() => step()) retry or poll loop, where every link has a single reaction, so a ranking by reactions per promise misses it. Every view also reads each root's reaction chain: the reactions reached by walking from a pending promise to its reactions, and from each reaction to the next pending promise (its derived promise, a capability, or a promise its handler keeps in scope, where a retry step keeps its next attempt). A cell reads 1 (chain 2,232) when one reaction on the root hides a long chain behind it, and the default view tracks the roots with the longest chains. A root still pending at settle with a longer chain than at the baseline rung (the last rung before run.json's fault window, else the first) is flagged: a loop a fault left waiting, which a root count reads as one pending promise.
  • memlab_retry_loops lists the pending retry, poll and backoff loops themselves, one row per loop: a pending promise root whose .then handler is named like a loop (retry, poll, backoff, reconnect, loop) or keeps an attempt counter (attempts, retries, backoff, …) in its own scope, and a pending timer (Node.js Timeout, a scheduler task record, a browser timer) whose captured callback source directly schedules itself (function tick() { …; setTimeout(tick, d); }) or is named like a loop. Names match as whole words in any case (scheduleRetry, sendHeartbeat; ApolloLink is not a poll). Indirect scheduling is not classified as a loop. When the source cannot be read (missing, truncated, over the parse cap, or not parseable as a module or a script), a timer whose callback reaches itself through its scope is listed as unconfirmed and reads pending (unconfirmed) at settle: a one-shot callback that another closure also captures looks the same in a snapshot. Each row prints the owner path, the attempt counter (its value when the snapshot has numbers, else numbers not captured), the reaction-chain length of a promise loop (or the pending timers of a timer loop) per rung, and PENDING or gone at settle. A loop is one promise or one timer at any moment, so the promise and timer counts read it as 1 while its backlog grows. Without a ladder it reads one snapshot (snapshot, default the active one). Loops first seen at settle are included, with missing driven values. Header totals count every detected loop, even when top limits the rows shown.

Who Holds the Growth​

  • memlab_cache_sole_retainer finds objects that only caches keep alive: objects the app has let go of. It computes what is reachable twice, once without passing through module-level caches (a Map or Set held by a module scope, an exported function, or a memoizer object), and attributes the difference to those caches. Over a ladder, it ranks caches by such objects gained per cycle.
  • memlab_bound_functions explains growth in the native_bind row of a class count: V8 names every fn.bind(...) result native_bind. It groups bound functions by target function and module, by receiver or first bound argument (a React useState setter is bound to its fiber, which names the component), and by the reference that holds them, then ranks the groups by growth per cycle.

Run One Query on Every Rung​

memlab_eval_across runs one memlab_eval program on each rung, without loading the rungs first. Give it paths, or a run_dir with rungs: [0, -1] (or ["c50", "last"]); include_settle: true adds the settle rung(s). With format: "table", when each rung returns a number or a flat object of numbers, the answer is one table with a column per rung and the change from first to last. With format: "json", the answer is one {rung: result} object for results of any shape (keyed by rung file name, a failed rung as {error: true}, a rung that left result unset as null; a name seen before, such as the same rung of two rounds, is keyed <name> (2)).

A path that names a snapshot already in memory (the same file by its path, a symlink, a hard link, or its .gz spelling) is read from memory instead of being parsed again; a file rewritten since it was parsed is parsed again. The header maps each path to the handle it read, for example Paths → handles: rung_00_c0.heapsnapshot → `rung_00_c0` (resident) · rung_03_c100.heapsnapshot → `rung_03_c100` (parsed in 13 s, kept in the rung cache), so the next call can pass handles instead. A handle can also be given as r<N> (the rung file rung_NN_…), first, last, settle or the file stem, here and in every tool that takes a snapshot (snapshot, baseline / target, handles), and rungs with run_dir takes r<N> too. A name that fits two resident snapshots, such as r0 with two rounds loaded, is refused with the list of residents and their aliases. Rungs that need a parse are parsed one at a time, and each one is reported as a progress step when the client sent a progress token.

Inside the program, helpers.rung is {label, index, of, cycles, isSettle} for the rung it is running on, and helpers.isSettle is true on the settle rung, so one program can treat the settle rung apart (in memlab_eval they describe the loaded snapshot, with index null):

memlab_eval_across({
run_dir: '/path/to/round',
include_settle: true,
format: 'json',
code: "result = helpers.isSettle ? {held: helpers.byClass('Draft').length} : {count: helpers.byClass('Draft').length}",
});

With compare: "growth", each rung returns {key: number} and the answer is one table of the keys that changed most, with no limit on how many keys the rungs return:

memlab_eval_across({
run_dir: '/path/to/round',
code: "result = Object.fromEntries(helpers.classCounts({type: 'object'}).map(c => [c.name, c.count]))",
compare: 'growth',
limit: 20,
});

Each row shows the value at every rung, the change from first to last, the change per cycle (from run.json, or from a _c<N> in the rung file name), the last-interval Δ, the rate per cycle of each interval, and a Shape (see How Growth Is Classified). With include_settle: true the settle rung is read as the end state rather than as another interval, so growth it gives back reads drains-at-settle. Only linear with a non-zero last-interval Δ that survives settle is a leak candidate. A key that is missing from a rung counts as 0 there. Keyed by helpers.stableKey(node), it shows which objects grew, in one call.

Save a Population Once, Use It Everywhere​

save_as: "name" on memlab_eval_across saves each rung's result as one named population when it is a list of node ids (an array or Set of ids or of nodes, or {ids: [...]}): one id list per rung, with the rung it came from. The reply prints the count at each rung, for example **Saved population `drafts`: 40 → 80 → 120 → 120 node id(s)** over 4 rung(s). An empty list counts as 0 at that rung. A rung whose result is not a list of node ids, or whose code failed, is named, and the leak gate then reads the population's Shape as unknown (the series has a gap).

memlab_validate_finding({population: "drafts"}) gates the per-rung counts on those rungs, with no ladder to pass: a rung named like a settle capture is the settle reading, and the class, owner and bound are read on the last driven rung. Other tools read one rung of it: pass population: "drafts" with snapshot naming the rung to memlab_retainer_summary, memlab_trace_all, memlab_what_if or memlab_island_doors. memlab_eval's save_as saves a one-snapshot population the same way. saved:<name> is the same as <name>; in memlab_validate_finding, a <kind>: prefix (class:, collection:, detached:, pending:, listener:) always reads as a kind, and a bare name that is saved reads as the saved population. Saved populations last for the session (until the server restarts), and memlab_server_status lists them with their counts.

Both eval tools also take:

  • code_file, a .js file to run instead of inline code.
  • use, a list of probe sets whose prelude runs first. Save setup that every probe repeats once, with memlab_probes({mode: "save", set, prelude}). With use and no code, memlab_eval_across runs the sets' probes themselves, one row per probe. It uses the set's saved run_dir when you pass no run_dir, paths or handles.

See Advanced Analysis for what eval programs can do.

Compare a Development and a Production Build​

memlab_build_pair_compare({dev_run_dir, prod_run_dir}) lines up a round on a development build with one on a production build. Field names survive minification, so populations are matched by their set of properties (and by class where the name isn't minified). Each population is reported as:

  • dev-only: it grows only on the development build.
  • production-real: it grows on the production build too.
  • production-saturating: it grows on the development build, but the second half of the production round grows less than 20% as fast as its first half, so on production it is bounded.
  • production-only: it grows only on the production build.

The summary says how much of the development build's growth per cycle the production build keeps.

Faster Repeat Analyses​

The first time a rung is loaded, the server writes an index file next to it (<snapshot>.memlab-index.json) with class counts, reference names and shape tables. Later ladder calls read the index instead of parsing the rung again: memlab_shape_census_diff with no filter takes seconds over a ladder that already has them.

Within one server process, work that several tools ask of the same parsed rung is done once and reused: the parsed index files (until either file changes on disk), the dev/automation reachability pass that memlab_leak_report, memlab_artifact_budget, memlab_explain_delta, memlab_ab_compare and memlab_cohort_owners all need, the artifact budget itself, and in memlab_eval the results of helpers.owner (at the default maxHops) and helpers.pathLabel. A rung that is parsed again, after it was evicted from memory, starts with empty caches.

The collection census of a rung (every Map, Set and Array, keyed by owner) is kept for the last 12 rung files, until the file changes on disk: memlab_collection_diff and memlab_verdict_table share it, so a repeat memlab_collection_diff, or one after a verdict table over the same rungs, parses no rung except, when a row it shows has not been profiled yet, the last one for its Keys column. Each rung is reported as a progress step (parsing, census, resident, census or census cached), which is what a background job's pct reads.

Long-Running Analyses​

Ladder analyses can take longer than the assistant waits for a tool call.

  • Background jobs. Start a tool with memlab_start_job and collect the result with memlab_job_status. memlab_load_snapshot({async: true}) and memlab_eval_across({async: true}) run in the background too. A ladder tool whose rungs predict more than 90 seconds (the parses, and for memlab_collection_diff the scan of rungs already in memory) starts as a job on its own and returns the job id; background: false keeps it in the foreground. A job runs in the server's own process, and a snapshot parse or heap scan is one synchronous step, so other calls wait until it returns, even ones that read no snapshot. A call that waited ends with "Waited up to ~N s before it ran …, behind background job …", so its time is not mistaken for its own. N is how long the job held the process; the call may have been sent at any point in it.
  • Waiting. memlab_job_status and memlab_battery_status take wait_ms, up to 90 seconds, so the call returns before a client gives up on it. A larger value is read as 90 seconds, with a note. A RUNNING reply says when it was written, so a late reply reads as stale. memlab_job_status also takes wait_s (the same wait in seconds) and returns the moment the job finishes. Until then its reply is one line, {"state": "running", "pct": 40, "eta_s": 55, "elapsed_s": 37}: the percent done comes from the rungs the job has reached (else from the time it was predicted to take), and pct or eta_s is null when neither is known. detail: "notes" adds the job's progress notes. memlab_eval_across({async: true}) over rungs that are all in memory, and predicted to take under 60 seconds, runs inline instead, as memlab_eval({background: true}) does.
  • Time limit. Every call runs under a 90-second limit by default, longer on heaps over 10 million nodes (9 µs per node). Every tool takes timeout_ms to change it for one call (0 for no limit, the eval scripts included), and MEMLAB_ANALYSIS_TIMEOUT_MS changes it for all calls. A scan that runs past it returns "analysis stopped" instead of blocking the server. memlab_sweep gives each section its own limit and lists the sections that ran out. memlab_collection_diff, memlab_eval_across, memlab_ab_compare and memlab_ladder_probe give each rung its own limit, scaled to the rung's file size, so a long ladder does not run out on its last rungs.
  • Jobs survive restarts. Job handles are written to ~/.memlab/jobs/ (MEMLAB_STATE_DIR), so a restarted server, or a second one, still answers for them: with the result, "running in another memlab server", or ORPHANED if the process running the job exited before it finished.

The server also frees memory on its own:

  • After 30 idle minutes, a long-running server unloads every snapshot except the active one (MEMLAB_IDLE_UNLOAD_MIN changes the delay).
  • With MEMLAB_RSS_SOFT_CAP_MB set, it unloads the snapshot used least recently, once a minute, while its memory use is above that cap.
  • memlab_server_status({all: true}) lists every memlab server process on the machine, with its parent, memory use and age, so a forgotten server holding gigabytes is easy to find.