Public: anyone can read this; the crew can change it.
A snapshot's full collection is a named job, so a stall line says when it held the loop (#17629) #17780
Merged 16h 5m ago, live in production
gc-as-job → main 0 commits
3 files
changed +37
−1
src/snapshot/settle.ts +6 −1
| @@ -10,8 +10,13 @@ | ||
| 10 | 10 | * |
| 11 | 11 | * What the VM holds is its JS heap plus its external memory: a chunk's fresh `Uint8Array` and |
| 12 | 12 | * `Buffer` bytes are counted as external, not as `heapUsed`. |
| 13 | * | |
| 14 | * A full collection runs as the job `snapshot-gc`, so a stall it held says `jobs snapshot-gc` | |
| 15 | * (#17629): the pass only awaiting across it read the same whether or not it had collected. | |
| 13 | 16 | */ |
| 14 | 17 | |
| 18 | import { during } from "../perf/jobs.ts"; | |
| 19 | ||
| 15 | 20 | /** Growth over the last full collection that earns a full one now. */ |
| 16 | 21 | const FORCE_AFTER_BYTES = 128 * 1024 * 1024; |
| 17 | 22 | |
| @@ -29,7 +34,7 @@ export const held = { | ||
| 29 | 34 | */ |
| 30 | 35 | export function settler( |
| 31 | 36 | heap: () => number = () => held.read(), |
| 32 | gc: (full: boolean) => void = (full) => void Bun.gc(full), | |
| 37 | gc: (full: boolean) => void = (full) => void (full ? during("snapshot-gc", () => Bun.gc(true)) : Bun.gc(false)), | |
| 33 | 38 | forceAfter = FORCE_AFTER_BYTES, |
| 34 | 39 | ): () => void { |
| 35 | 40 | let floor = heap(); |
test/job-slices.test.ts +1
| @@ -298,6 +298,7 @@ function jobs(): Record<string, () => unknown> { | ||
| 298 | 298 | * on. |
| 299 | 299 | */ |
| 300 | 300 | const UNTIMED: Record<string, string> = { |
| 301 | "snapshot-gc": "one full Bun.gc(true) while a snapshot is cut (snapshot/settle.ts), as long as the process's own heap makes it, which a fixture's heap does not; snapshot-settle.test.ts drives it", | |
| 301 | 302 | "kept-log-flush": "every 2 s: one append of the buffered stall and minute lines to perf/loop.log, rotated past its size (perf/kept_log.ts); perf-kept-log.test.ts drives flush directly", |
| 302 | 303 | "snapshot-cut-timeout": "a one-shot timer per file a snapshot cuts (snapshot/cut.ts), fired only when the cutter's worker has not answered within CUT_TIMEOUT_MS: it ends the worker and refuses the jobs it held; snapshot-cut.test.ts drives a silent worker to it", |
| 303 | 304 | "advisory-feed": "hourly (and once 30 s after boot): one read of each repository's lockfile and two network fetches, KEV and OSV (core/advisory_feed.ts); the network is not timed here and advisory-feed.test.ts drives listenOnce with a fake fetch", |
test/snapshot-settle.test.ts +30
| @@ -1,4 +1,6 @@ | ||
| 1 | 1 | import { expect, test } from "bun:test"; |
| 2 | import { jobsOf } from "../src/perf/jobs.ts"; | |
| 3 | import { createLoopWatch, stallLine } from "../src/perf/loop.ts"; | |
| 2 | 4 | import { held, settler } from "../src/snapshot/settle.ts"; |
| 3 | 5 | |
| 4 | 6 | test("a heap that outgrows its last full collection is collected to the end, then watched from there (#17558)", () => { |
| @@ -49,3 +51,31 @@ test("settler() reads what the VM holds through held.read and runs a full collec | ||
| 49 | 51 | (Bun as { gc: unknown }).gc = realGc; |
| 50 | 52 | } |
| 51 | 53 | }); |
| 54 | ||
| 55 | test("a full collection is named in the stall it held; one that is only asked for is not (#17629)", () => { | |
| 56 | const realGc = Bun.gc; | |
| 57 | // A collection that holds the thread for 30 ms, as a full one does on a large heap. | |
| 58 | (Bun as { gc: unknown }).gc = () => { | |
| 59 | const until = performance.now() + 30; | |
| 60 | while (performance.now() < until) { | |
| 61 | /* collect */ | |
| 62 | } | |
| 63 | }; | |
| 64 | try { | |
| 65 | let heap = 0; | |
| 66 | const settle = settler(() => heap, undefined, 100); | |
| 67 | const jobs = jobsOf({}); | |
| 68 | const across = (): string => { | |
| 69 | const from = performance.now(); | |
| 70 | settle(); | |
| 71 | const at = performance.now(); | |
| 72 | const watch = createLoopWatch(10, () => [], () => [], jobs.held); | |
| 73 | return stallLine(watch.stalled(at - from, at)!); | |
| 74 | }; | |
| 75 | expect(across()).not.toContain("snapshot-gc"); | |
| 76 | heap = 100; | |
| 77 | expect(across()).toContain("no request; jobs snapshot-gc"); | |
| 78 | } finally { | |
| 79 | (Bun as { gc: unknown }).gc = realGc; | |
| 80 | } | |
| 81 | }); |
new above
offline