Skip to content

Cap maxWorkers and bump heap to bound Fantom Metro memory (#56529)#56529

Closed
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D101791795
Closed

Cap maxWorkers and bump heap to bound Fantom Metro memory (#56529)#56529
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D101791795

Conversation

@rubennorte

@rubennorte rubennorte commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary:

Fantom runs every test through a single shared Metro server (started in
globalSetup). Jest's default maxWorkers is numCpus - 1, so on a
high-core box (e.g. 176 CPUs) ~175 workers fire bundle requests at Metro
concurrently. Each in-flight request makes Metro materialize a full
dependency Graph (transformed modules, source maps, inverse-deps,
file-watcher subscription), which is hundreds of MB.

The per-test DELETE eviction added in D101652820 only releases that
memory after the bundle response completes, so the simultaneous in-flight
set still blows past the previous Node --max-old-space-size=8192 ceiling
in scripts/fantom.sh — the Metro process aborts with
FATAL ERROR: Ineffective mark-compacts near heap limit after just a
handful of test suites.

Two coordinated changes that balance throughput and safety:

  • scripts/fantom.sh: bump the Node heap from 8 GB to 16 GB so we have
    headroom over the observed steady-state peak.
  • private/react-native-fantom/config/jest.config.js: cap maxWorkers
    at min(numCpus - 1, 16). With 8 workers the heap peaked at ~3 GB
    (~400 MB / worker), so 16 workers fits comfortably under a 16 GB cap
    with ~40% headroom.

This is intentionally a balance rather than a hard worker cap — bumping
the heap alone would still leave 100+ in-flight graphs racing GC, and
capping workers alone leaves throughput on the table on big machines.

Changelog: [Internal]

Reviewed By: andrewdacenko

Differential Revision: D101791795

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 21, 2026
@meta-codesync

meta-codesync Bot commented Apr 21, 2026

Copy link
Copy Markdown

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D101791795.

@meta-codesync meta-codesync Bot changed the title Cap maxWorkers and bump heap to bound Fantom Metro memory Cap maxWorkers and bump heap to bound Fantom Metro memory (#56529) Apr 21, 2026
rubennorte added a commit to rubennorte/react-native that referenced this pull request Apr 21, 2026
Summary:

Fantom runs every test through a single shared Metro server (started in
`globalSetup`). Jest's default `maxWorkers` is `numCpus - 1`, so on a
high-core box (e.g. 176 CPUs) ~175 workers fire bundle requests at Metro
concurrently. Each in-flight request makes Metro materialize a full
dependency `Graph` (transformed modules, source maps, inverse-deps,
file-watcher subscription), which is hundreds of MB.

The per-test `DELETE` eviction added in D101652820 only releases that
memory after the bundle response completes, so the simultaneous in-flight
set still blows past the previous Node `--max-old-space-size=8192` ceiling
in `scripts/fantom.sh` — the Metro process aborts with
`FATAL ERROR: Ineffective mark-compacts near heap limit` after just a
handful of test suites.

Two coordinated changes that balance throughput and safety:

- `scripts/fantom.sh`: bump the Node heap from 8 GB to 16 GB so we have
  headroom over the observed steady-state peak.
- `private/react-native-fantom/config/jest.config.js`: cap `maxWorkers`
  at `min(numCpus - 1, 16)`. With 8 workers the heap peaked at ~3 GB
  (~400 MB / worker), so 16 workers fits comfortably under a 16 GB cap
  with ~40% headroom.

This is intentionally a balance rather than a hard worker cap — bumping
the heap alone would still leave 100+ in-flight graphs racing GC, and
capping workers alone leaves throughput on the table on big machines.

Changelog: [Internal]

Differential Revision: D101791795
Summary:
Pull Request resolved: react#56529

Fantom runs every test through a single shared Metro server (started in
`globalSetup`). Jest's default `maxWorkers` is `numCpus - 1`, so on a
high-core box (e.g. 176 CPUs) ~175 workers fire bundle requests at Metro
concurrently. Each in-flight request makes Metro materialize a full
dependency `Graph` (transformed modules, source maps, inverse-deps,
file-watcher subscription), which is hundreds of MB.

The per-test `DELETE` eviction added in D101652820 only releases that
memory after the bundle response completes, so the simultaneous in-flight
set still blows past the previous Node `--max-old-space-size=8192` ceiling
in `scripts/fantom.sh` — the Metro process aborts with
`FATAL ERROR: Ineffective mark-compacts near heap limit` after just a
handful of test suites.

Two coordinated changes that balance throughput and safety:

- `scripts/fantom.sh`: bump the Node heap from 8 GB to 16 GB so we have
  headroom over the observed steady-state peak.
- `private/react-native-fantom/config/jest.config.js`: cap `maxWorkers`
  at `min(numCpus - 1, 16)`. With 8 workers the heap peaked at ~3 GB
  (~400 MB / worker), so 16 workers fits comfortably under a 16 GB cap
  with ~40% headroom.

This is intentionally a balance rather than a hard worker cap — bumping
the heap alone would still leave 100+ in-flight graphs racing GC, and
capping workers alone leaves throughput on the table on big machines.

Changelog: [Internal]

Reviewed By: andrewdacenko

Differential Revision: D101791795
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @rubennorte in 0f9b8e4

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 21, 2026
@meta-codesync

meta-codesync Bot commented Apr 21, 2026

Copy link
Copy Markdown

This pull request has been merged in 0f9b8e4.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants