-
Notifications
You must be signed in to change notification settings - Fork 4.7k
GarbageCollectionController: fire up to 2 Full GCs before going to slow interval #29280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
411553f
GarbageCollectionController: fire up to 2 Full GCs at the fast→slow t…
Jarred-Sumner 5ca3228
review: #-prefix field, cancel reduction on any .fast, gate Full on f…
Jarred-Sumner 6eb16c6
fix: don't cancel idle reduction when GC shrinks heap
Jarred-Sumner af48886
review: gate .fast resets on slow->fast transition; treat non-growth …
Jarred-Sumner d2332a4
keep gc_last_heap_size owned by the allocation-driven path
robobun fcf2215
read BUN_GC_TIMER_* from process env; add idle Full GC test
robobun d7d1d1d
ci: retrigger (51635 x64-musl agent InsufficientInstanceCapacity + ch…
robobun a52ca18
track GC-driven shrinks in .pending so re-growth is detected
robobun c38b227
cancel idle reduction when the allocation path sees growth; register …
robobun 65317cf
reset stable-tick counter when entering reduction mode
robobun 43b43ef
test: widen idle window for loaded darwin-x64 hosts
robobun ba8e8de
ci: retrigger (51722 linux/darwin-x64 build-zig/build-cpp agents expi…
robobun 1e35f93
Merge branch 'main' into jarred/idle-full-gc
alii 1b0e65e
Merge branch 'main' into jarred/idle-full-gc
alii 3fb4b84
Merge branch 'main' into jarred/idle-full-gc
alii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe } from "harness"; | ||
|
|
||
| // The repeating GC timer's collectAsync() lets JSC pick Eden vs Full. At idle | ||
| // JSC keeps picking Eden because Heap::updateAllocationLimits ratchets | ||
| // m_maxHeapSize on every Eden GC, so the 1/3 Full-promotion ratio stays above | ||
| // the threshold instead of crossing it. Before #29280 this meant old-gen | ||
| // garbage was never reclaimed while idle. Now, after 30 stable fast ticks, | ||
| // the controller fires an explicit collectAsync(CollectionScope::Full). | ||
|
|
||
| const fixture = /* js */ ` | ||
| import { heapSize, fullGC } from "bun:jsc"; | ||
|
|
||
| // ~40 MB of JS-heap-resident data. | ||
| let data = []; | ||
| for (let i = 0; i < 5000; i++) data.push(new Array(1000).fill(i)); | ||
|
|
||
| // fullGC() while still referenced promotes everything to old gen and sets | ||
| // m_maxHeapSize = proportionalHeapSize(~40 MB), which is large enough that | ||
| // the post-release edenToOldGenerationRatio stays >= 1/3 and JSC's own | ||
| // shouldDoFullCollection() heuristic never fires. This is the shape a | ||
| // long-running server reaches organically; we force it here so the test is | ||
| // deterministic. | ||
| fullGC(); | ||
| fullGC(); | ||
|
|
||
| data = null; | ||
|
|
||
| const initial = heapSize(); | ||
| process.stdout.write(\`INITIAL=\${initial}\\n\`); | ||
|
|
||
| // Keep the event loop alive without allocating. With BUN_GC_TIMER_INTERVAL=20 | ||
| // the controller ticks every 20ms; once it sees 30 non-growing ticks (~600ms) | ||
| // it requests an async Full GC and converges to the slow interval. 5s of | ||
| // pure idle gives ~8x headroom for loaded darwin-x64 hosts where uws timers | ||
| // can be coalesced to coarser effective intervals under CPU pressure. | ||
| await Bun.sleep(5000); | ||
|
|
||
| // The Full GC is async — poll until its result is visible in heapSize(). | ||
| // Without the idle Full GC the loop runs to completion with heap unchanged. | ||
| const threshold = initial / 4; | ||
| let final = heapSize(); | ||
| for (let i = 0; i < 30 && final >= threshold; i++) { | ||
| await Bun.sleep(100); | ||
| final = heapSize(); | ||
| } | ||
| process.stdout.write(\`FINAL=\${final}\\n\`); | ||
| `; | ||
|
|
||
| test("GC controller fires a Full GC at idle so old-gen garbage is reclaimed", async () => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "-e", fixture], | ||
| env: { | ||
| ...bunEnv, | ||
| BUN_GC_TIMER_INTERVAL: "20", | ||
| }, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect(stderr).toBe(""); | ||
|
|
||
| const initial = Number(/INITIAL=(\d+)/.exec(stdout)?.[1]); | ||
| const final = Number(/FINAL=(\d+)/.exec(stdout)?.[1]); | ||
| expect(initial).toBeGreaterThan(20 * 1024 * 1024); | ||
| expect(Number.isFinite(final)).toBe(true); | ||
|
|
||
| // Without the idle Full GC, the repeating timer only runs Eden collections | ||
| // and `final` stays within a few hundred KB of `initial`. With it, the | ||
| // ~40 MB of promoted arrays is reclaimed and the heap drops to ~1 MB. | ||
| expect(final).toBeLessThan(initial / 4); | ||
|
|
||
| expect(exitCode).toBe(0); | ||
| }, 30_000); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.