Skip to content

Heap: make minEdenToOldGenerationRatio a JSC option - #332

Merged
Jarred-Sumner merged 1 commit into
mainfrom
robobun/min-eden-to-old-generation-ratio-option
Jul 24, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
robobun/min-eden-to-old-generation-ratio-option

Conversation

@robobun

@robobun robobun commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

The 1.0 / 3.0 constant in Heap::updateAllocationLimits() schedules a full collection after an eden GC whenever remainingHeapSize / maxHeapSize falls below it.

Since maxHeapSize = growthFactor * live and remainingHeapSize ≈ (growthFactor - 1) * live in steady state, the condition reduces to (growthFactor - 1) / growthFactor < ratio, i.e. growthFactor < 1 / (1 - ratio). At the current ratio = 1/3 this is 1.5: any proportional heap growth factor below 1.5 promotes every eden GC to a full GC.

This makes it an Options::minEdenToOldGenerationRatio() with the same 1.0 / 3.0 default, so behavior is unchanged. Lowering it (e.g. to 0.2) drops the growth-factor floor to 1.25, which lets embedders run tighter heapGrowthMaxIncrease / smallHeapGrowthFactor values without thrash.

Measured on Bun 1.4.0 release, linux-x64, across tsc 5.9, next build --webpack, and express/fastify/elysia/node:http under load:

growth factor express full GCs /15s express CPU s express RSS MB
1.3 183 55 342
1.5 180 55 342
1.75 4 22 345
2.0 3 22 354

The cliff between 1.5 and 1.75 is this constant. Full writeup and harness at bench/heap-growth/REPORT.md.

The 1/3 constant in Heap::updateAllocationLimits() schedules a full
collection after an eden GC whenever remainingHeapSize / maxHeapSize
falls below it. Since maxHeapSize = growthFactor * live and
remainingHeapSize is approximately (growthFactor - 1) * live in steady
state, this bounds the effective heap growth factor below at
1 / (1 - ratio) = 1.5. Any growth factor under 1.5 promotes every eden
GC to full.

Exposing it as Options::minEdenToOldGenerationRatio() (same 1/3 default,
no behavior change) lets embedders tune the growth factors below 1.5
without inducing full-GC thrash.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 86f09999-62be-46d6-86ce-72c3951ca006

📥 Commits

Reviewing files that changed from the base of the PR and between 1acceb9 and 592645e.

📒 Files selected for processing (2)
  • Source/JavaScriptCore/heap/Heap.cpp
  • Source/JavaScriptCore/runtime/OptionsList.h

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical hoist of a hardcoded constant into a JSC option with an identical default.

What was reviewed:

  • Confirmed the new Options::minEdenToOldGenerationRatio() default (1.0 / 3.0) matches the removed local, so default behavior is unchanged.
  • Option entry follows the same v(Double, ..., Normal, ...) pattern as the adjacent heap-growth options in OptionsList.h.
  • No other references to minEdenToOldGenerationRatio in the tree; the single call site in Heap::updateAllocationLimits() is the only consumer.
Extended reasoning...

Overview

This PR replaces a hardcoded local constant double minEdenToOldGenerationRatio = 1.0 / 3.0 in Heap::updateAllocationLimits() with a new JSC runtime option Options::minEdenToOldGenerationRatio(). The option is registered in OptionsList.h alongside the other heap-growth tuning knobs (smallHeapGrowthFactor, heapGrowthMaxIncrease, etc.) with the same 1.0 / 3.0 default and a descriptive help string. Two files, three effective lines changed.

Security risks

None. This is a GC scheduling heuristic threshold. The option uses Normal availability, consistent with every neighboring heap-tuning option, and is only settable via the standard JSC_* env / Options:: mechanism before VM finalization. Misconfiguration could only affect GC frequency (perf/RSS), not memory safety or isolation.

Level of scrutiny

Low. This is a textbook constant-to-option hoist with an unchanged default — a pattern used hundreds of times in this exact macro list. The comparison at the call site (edenToOldGenerationRatio < Options::minEdenToOldGenerationRatio()) is semantically identical to the removed code when the option is left at its default. There is no new control flow, no type change, and Options::foo() accessors are trivially inlined reads from the frozen OptionsStorage.

Other factors

  • Grep confirms the only two occurrences of minEdenToOldGenerationRatio are the definition and the single use site — no stale references.
  • The PR description includes a clear derivation of why the constant matters and benchmark data motivating configurability, but the code change itself does not alter any default.
  • The upstream WebKit CODEOWNERS lists @WebKit/jsc-reviewers for all of Source/JavaScriptCore; that is inherited upstream config and applies to essentially every change in this fork, so it is not treated as a per-PR gate here.
  • No prior reviewer comments to address; the only timeline entry is a CodeRabbit rate-limit notice.

@github-actions

Copy link
Copy Markdown

Preview Builds

Commit Release Date
592645e4 autobuild-preview-pr-332-592645e4 2026-07-24 11:18:46 UTC

robobun added a commit to oven-sh/bun that referenced this pull request Jul 24, 2026
…pdated recommendations

With minEdenToOldGenerationRatio exposed (oven-sh/WebKit#332), ratio=0.2
moves the thrash floor from growth-factor 1.5 to 1.25, enabling
heapGrowthMaxIncrease=0.5 / smallHeapGrowthFactor=1.5 safely.

tsc peak RSS: 1035 MB (current) -> 800 MB (-23%) at +3% wall.
Servers: RSS unchanged, no thrash.
@Jarred-Sumner
Jarred-Sumner merged commit b11589f into main Jul 24, 2026
43 checks passed
@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

@claude now that this is merged and the release artifacts have had time to build, please open a PR in oven-sh/bun that bumps WEBKIT_VERSION in scripts/build/deps/webkit.ts to this merge commit, b11589facf18131ca86b70767a0c46d9ea81b7d0, so Options::minEdenToOldGenerationRatio becomes available to Bun. No other changes needed in that PR — the default is unchanged, so it's behavior-preserving; setting the option to a non-default value can come in a separate follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants