Public: anyone can read this; the crew can change it.

Sentinel: memory-growth was degraded 14 minutes today: The forge's own memory is 4287 MiB, over twice its first-hour 1716 MiB and past the 2176 MiB more its database caches m… #17561

opened this

Merged 15h 50m ago, live in production

The snapshot and the stream pass now run a full garbage collection when the asked one falls behind. This is the fourth fix for the same growth, and I have not shown that it is the whole cause. I could not read production's data, so the next finding's memory heap main line will say.

Notes

opened this

The snapshot and the stream pass now run a full garbage collection when the asked one falls behind. This is the fourth fix for the same growth, and I have not shown that it is the whole cause. I could not read production's data, so the next finding's memory heap main line will say. tsc, test/snapshot-settle.test.ts, test/snapshot-stream.test.ts and test/unused-exports.test.ts pass; the gate printed nothing. I did not run the full suite. The forge's own check does that on the push.

What the finding showed. snapshot-stream was open before the trip, and the main JS heap went from 416 MiB in the first hour to 1927 MiB at the trip and 2655 MiB afterwards. Every held count was flat, so this looks like garbage rather than a holder. This release already had #17434 (collect between forges) and #17493/#17494 (collect each 256 MiB read), and the heap still ran away. Both of those call Bun.gc(false), which only asks for a collection and returns. On a heap this size the ask did not keep up.

What changed.

  • New module: src/snapshot/settle.ts adds settler(). It keeps the asked Bun.gc(false) as the normal step.
  • When it forces: once the main heap stands 512 MiB above where the last full collection left it, it runs Bun.gc(true) and measures from there.
  • Where it is used: takeSnapshot (every 256 MiB read) and streamPass (between forges) both use it, replacing the inline Bun.gc(false) calls.
  • Tests and docs: test/snapshot-settle.test.ts covers the threshold, the full collection and the reset. docs/features/memory-growth.md has a new #17558 paragraph.

What I chose not to do.

  • I did not make every collection a full one. A full collection holds the loop for a few hundred ms on a live heap of a few hundred MiB, so it runs only when the heap has clearly outgrown the last one.
  • I did not touch the memory outside every heap (1143 to 1677 MiB at the trip), which is the smaller part of the growth.

To check. memory-growth should stay out of the degraded list for a day, or hold under 10 minutes. If the trip's memory heap main line is still far above its first hour with snapshot-stream open, the garbage is not coming from the snapshot's buffers. The next step would be the heap census, or FORGE_HEAP_CAPTURE_DIR on a copy of production's data.

🤖 Generated with Claude Code

Closes #17558

commented

The snapshot and the stream pass now run a full garbage collection when the asked one falls behind. This is the fourth fix for the same growth, and I have not shown that it is the whole cause. I could not read production's data, so the next finding's memory heap main line will say. tsc, test/snapshot-settle.test.ts, test/snapshot-stream.test.ts and test/unused-exports.test.ts pass; the gate printed nothing. I did not run the full suite. The forge's own check does that on the push.

What the finding showed. snapshot-stream was open before the trip, and the main JS heap went from 416 MiB in the first hour to 1927 MiB at the trip and 2655 MiB afterwards. Every held count was flat, so this looks like garbage rather than a holder. This release already had #17434 (collect between forges) and #17493/#17494 (collect each 256 MiB read), and the heap still ran away. Both of those call Bun.gc(false), which only asks for a collection and returns. On a heap this size the ask did not keep up.

What changed.

  • New module: src/snapshot/settle.ts adds settler(). It keeps the asked Bun.gc(false) as the normal step.
  • When it forces: once the main heap stands 512 MiB above where the last full collection left it, it runs Bun.gc(true) and measures from there.
  • Where it is used: takeSnapshot (every 256 MiB read) and streamPass (between forges) both use it, replacing the inline Bun.gc(false) calls.
  • Tests and docs: test/snapshot-settle.test.ts covers the threshold, the full collection and the reset. docs/features/memory-growth.md has a new #17558 paragraph.

What I chose not to do.

  • I did not make every collection a full one. A full collection holds the loop for a few hundred ms on a live heap of a few hundred MiB, so it runs only when the heap has clearly outgrown the last one.
  • I did not touch the memory outside every heap (1143 to 1677 MiB at the trip), which is the smaller part of the growth.

To check. memory-growth should stay out of the degraded list for a day, or hold under 10 minutes. If the trip's memory heap main line is still far above its first hour with snapshot-stream open, the garbage is not coming from the snapshot's buffers. The next step would be the heap census, or FORGE_HEAP_CAPTURE_DIR on a copy of production's data.

🤖 Generated with Claude Code

commented

Both changes are in and pushed. tsc is clean. test/snapshot-settle.test.ts and test/snapshot-stream.test.ts pass, and test/unused-exports.test.ts passed when I ran it (before the final commit). I did not run the full suite; the forge's own check does that on the push.

What changed

  • Wiring test. test/snapshot-stream.test.ts now checks both defaults. It replaces what the VM holds (held.read) and Bun.gc, then:
    • runs streamPass with its default settle, using a take that raises the reading by 1 GiB;
    • runs takeSnapshot with its default settle and settleBytes: 1.

    Both must call Bun.gc(true). I put the old Bun.gc(false) back in stream.ts and the new test failed, so it does catch the revert. I did not repeat that check for takeSnapshot's default.

  • External memory. The trigger reads heapUsed + max(external, arrayBuffers). It uses max because arrayBuffers is normally part of external, and adding both would count the same bytes twice. A test sets process.memoryUsage to confirm that external bytes count.
  • Docs. docs/features/memory-growth.md now says the trigger counts JS heap plus external memory.
  • One reading per call. settler() reads once per settle() call. After a full collection it reads once more to set the new baseline, because the number has changed by then.

Not done: I did not add RSS to the trigger. RSS also includes malloc and SQLite memory that a collection cannot return, so a full collection triggered by it could run over and over without freeing anything.

Still unmeasured on production's data. The next finding's memory heap main line will show whether this was the whole cause.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs