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

opened this

Merged 16h 5m ago, live in production

gc-as-job → main 0 commits

  • Merged. gc-as-job was merged into main as dc59f97.

Review

Sign in to review this change.
3 files changed +37 −1
src/snapshot/settle.ts +6 −1
@@ -10,8 +10,13 @@
1010 *
1111 * What the VM holds is its JS heap plus its external memory: a chunk's fresh `Uint8Array` and
1212 * `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.
1316 */
1417
18 import { during } from "../perf/jobs.ts";
19
1520 /** Growth over the last full collection that earns a full one now. */
1621 const FORCE_AFTER_BYTES = 128 * 1024 * 1024;
1722
@@ -29,7 +34,7 @@ export const held = {
2934 */
3035 export function settler(
3136 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)),
3338 forceAfter = FORCE_AFTER_BYTES,
3439 ): () => void {
3540 let floor = heap();
test/job-slices.test.ts +1
@@ -298,6 +298,7 @@ function jobs(): Record<string, () => unknown> {
298298 * on.
299299 */
300300 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",
301302 "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",
302303 "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",
303304 "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 @@
11 import { expect, test } from "bun:test";
2 import { jobsOf } from "../src/perf/jobs.ts";
3 import { createLoopWatch, stallLine } from "../src/perf/loop.ts";
24 import { held, settler } from "../src/snapshot/settle.ts";
35
46 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
4951 (Bun as { gc: unknown }).gc = realGc;
5052 }
5153 });
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 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs