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

A child forge's Bun processes start with a smaller heap, with the resident memory before and after in the pull #15273

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A child forge's own Bun process now starts with --smol, Bun's smaller-heap mode (#15256). Setting FORGECHILDSMOL=off on the parent turns it off; any other value, or none, leaves it on. What changed src/settings/childheap.ts (new) is the one place the start command is built.

Notes

shipped production is serving it deploy cfe12e4

opened this

A child forge's own Bun process now starts with --smol, Bun's smaller-heap mode (#15256). Setting FORGE_CHILD_SMOL=off on the parent turns it off; any other value, or none, leaves it on.

What changed

  • src/settings/child_heap.ts (new) is the one place the start command is built. It has childSmol(env), childArgs(execPath, main, env) and the quoted childCommand shell line.
  • src/spawn/cell.ts now calls childCommand(process.execPath, source.main) instead of building its own exec line.
  • docs/features/memory-held.md records the change, the measurements, and what is still not done.

Measured in this sandbox: Bun 1.4.4, the real src/main.ts left idle, empty data dir, one run per mode, resident size from /proc/<pid>/status:

without --smolwith --smol
resident at 30 s / 60 s / 90 s idle279 / 281 / 282 MiB257 / 262 / 262 MiB
resident after 60 loads of /305 MiB289 MiB
GET / median / p903.4 / 4.6 ms4.1 / 9.3 ms

That is about 20 MiB (7%) less for an idle child. Requests got somewhat slower, especially at p90, which matches the risk the issue names: more frequent garbage collection costs CPU. These are single runs and the without---smol run shared the machine with a failed boot, so read the timings as rough. A 7% cut on its own does not explain or prevent the 4.7 GiB growth in #15210.

Not done

  • The processes a child starts in turn (its checks, crew runs and apps) do not get --smol. A command-line flag only reaches the process it starts.
  • No page change, so no review steps.

Tests: test/child-heap-smol.test.ts:

  • the default arguments carry --smol, and FORGE_CHILD_SMOL=off drops it;
  • the shell line quotes each argument;
  • a process started from the real shell line reports --smol in process.execArgv, and does not when the switch is off;
  • cell.ts builds its command through childCommand. This one fails without the change.

Checks run: the new test, spawn-cell, spawn-small-cell, spawn-cell-real-child, hosted-child-cells and memory-hold all pass, with 5 tests skipped. The skips are the unix-socket cases, which this sandbox can't run (FORGE_TEST_SOCKET=port); the forge's check runs them on push. bun scripts/gate.ts --fix (it rewrapped one comment, committed) and bun x tsc --noEmit are clean. scripts/fast.ts named 3,297 test files for this diff, far beyond running here, so I picked the cell and memory tests above instead.

To try it: bun test test/child-heap-smol.test.ts. On a parent, start a child and look at its command line with ps to see --smol; set FORGE_CHILD_SMOL=off on the parent and it is gone.

🤖 Generated with Claude Code

Closes #15256

commented

A child forge's own Bun process now starts with --smol, Bun's smaller-heap mode (#15256). Setting FORGE_CHILD_SMOL=off on the parent turns it off; any other value, or none, leaves it on.

What changed

  • src/settings/child_heap.ts (new) is the one place the start command is built. It has childSmol(env), childArgs(execPath, main, env) and the quoted childCommand shell line.
  • src/spawn/cell.ts now calls childCommand(process.execPath, source.main) instead of building its own exec line.
  • docs/features/memory-held.md records the change, the measurements, and what is still not done.

Measured in this sandbox: Bun 1.4.4, the real src/main.ts left idle, empty data dir, one run per mode, resident size from /proc/<pid>/status:

without --smolwith --smol
resident at 30 s / 60 s / 90 s idle279 / 281 / 282 MiB257 / 262 / 262 MiB
resident after 60 loads of /305 MiB289 MiB
GET / median / p903.4 / 4.6 ms4.1 / 9.3 ms

That is about 20 MiB (7%) less for an idle child. Requests got somewhat slower, especially at p90, which matches the risk the issue names: more frequent garbage collection costs CPU. These are single runs and the without---smol run shared the machine with a failed boot, so read the timings as rough. A 7% cut on its own does not explain or prevent the 4.7 GiB growth in #15210.

Not done

  • The processes a child starts in turn (its checks, crew runs and apps) do not get --smol. A command-line flag only reaches the process it starts.
  • No page change, so no review steps.

Tests: test/child-heap-smol.test.ts:

  • the default arguments carry --smol, and FORGE_CHILD_SMOL=off drops it;
  • the shell line quotes each argument;
  • a process started from the real shell line reports --smol in process.execArgv, and does not when the switch is off;
  • cell.ts builds its command through childCommand. This one fails without the change.

Checks run: the new test, spawn-cell, spawn-small-cell, spawn-cell-real-child, hosted-child-cells and memory-hold all pass, with 5 tests skipped. The skips are the unix-socket cases, which this sandbox can't run (FORGE_TEST_SOCKET=port); the forge's check runs them on push. bun scripts/gate.ts --fix (it rewrapped one comment, committed) and bun x tsc --noEmit are clean. scripts/fast.ts named 3,297 test files for this diff, far beyond running here, so I picked the cell and memory tests above instead.

To try it: bun test test/child-heap-smol.test.ts. On a parent, start a child and look at its command line with ps to see --smol; set FORGE_CHILD_SMOL=off on the parent and it is gone.

🤖 Generated with Claude Code

commented

A child forge's own Bun process now starts with --smol, Bun's smaller-heap mode (#15256). Setting FORGE_CHILD_SMOL=off on the parent turns it off; any other value, or none, leaves it on.

What changed

  • src/settings/child_heap.ts (new) is the one place the start command is built. It has childSmol(env), childArgs(execPath, main, env) and the quoted childCommand shell line.
  • src/spawn/cell.ts now calls childCommand(process.execPath, source.main) instead of building its own exec line.
  • docs/features/memory-held.md records the change, the measurements, and what is still not done.
  • A second commit carries the Replaces: and Direction: lines the gate requires (#15210 → #15256). Nothing in the code changed for it.

Measured in this sandbox: Bun 1.4.4, the real src/main.ts left idle, empty data dir, one run per mode, resident size from /proc/<pid>/status:

without --smolwith --smol
resident at 30 s / 60 s / 90 s idle279 / 281 / 282 MiB257 / 262 / 262 MiB
resident after 60 loads of /305 MiB289 MiB
GET / median / p903.4 / 4.6 ms4.1 / 9.3 ms

That is about 20 MiB (7%) less for an idle child. Requests got somewhat slower, especially at p90, which matches the risk the issue names: more frequent garbage collection costs CPU. These are single runs and the without---smol run shared the machine with a failed boot, so read the timings as rough. A 7% cut on its own does not explain or prevent the 4.7 GiB growth in #15210.

Not done

  • The processes a child starts in turn (its checks, crew runs and apps) do not get --smol. A command-line flag only reaches the process it starts.
  • No page change, so no review steps.

Tests: test/child-heap-smol.test.ts:

  • the default arguments carry --smol, and FORGE_CHILD_SMOL=off drops it;
  • the shell line quotes each argument;
  • a process started from the real shell line reports --smol in process.execArgv, and does not when the switch is off;
  • cell.ts builds its command through childCommand. This one fails without the change.

Checks run: the new test, spawn-cell, spawn-small-cell, spawn-cell-real-child, hosted-child-cells and memory-hold all pass, with 5 tests skipped. The skips are the unix-socket cases, which this sandbox can't run (FORGE_TEST_SOCKET=port); the forge's check runs them on push. bun scripts/gate.ts passes after the second commit and bun x tsc --noEmit was clean. scripts/fast.ts named 3,297 test files for this diff, far beyond running here, so I picked the cell and memory tests above instead.

To try it: bun test test/child-heap-smol.test.ts. On a parent, start a child and look at its command line with ps to see --smol; set FORGE_CHILD_SMOL=off on the parent and it is gone.

🤖 Generated with Claude Code

Approved

Small, single-purpose, one module (src/settings/child_heap.ts), cell.ts routes through it, a real-process test proves --smol reaches execArgv and that off removes it, docs in docs/features/memory-held.md (not README). No page change, so no look steps. Two things next: (1) src/release/small_forge.ts:159 also starts a forge in a cell and still has no --smol; route it through childArgs or say why not. (2) The p90 for GET / went 4.6 to 9.3 ms on single runs; repeat the measurement a few times so the cost is known before this is relied on. Also the last test greps cell.ts source text; it is brittle, a behavioural test of the registry start would be better.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs