Skip to content

Support os.availableParallelism() in static programs - #836

Open
cramforce wants to merge 1 commit into
perf/alloc-hugepagesfrom
perf/parmem
Open

cramforce wants to merge 1 commit into
perf/alloc-hugepagesfrom
perf/parmem

Conversation

@cramforce

Copy link
Copy Markdown
Contributor

Adds os.availableParallelism() to static-native programs, matching Node/libuv: the CPU affinity mask, reduced by the cgroup CPU quota on Linux, and the logical CPU count elsewhere. Verified against Node on macOS and on Linux under affinity 0-7, 0-31 and 3. tsc-ts uses it to size its parse threads and pick a default checker count (TSC_TS_CHECKERS=auto). New corpus program 4598-os-available-parallelism; Node compatibility manifests regenerated. Stacked on #830.

The runtime answers like libuv 1.51's uv_available_parallelism, which
Node's os.availableParallelism() returns: on Linux the CPUs in the
process's affinity mask, lowered to a smaller cgroup (v2 cpu.max or v1
CFS) CPU quota; on Darwin hw.activecpu, hw.logicalcpu or hw.ncpu; on
Windows GetSystemInfo's processor count; at least 1. WASI answers 1, as
the dynamic island does.

Parallel programs (tsc-ts --checkers) need it to size their thread pools.
Corpus 4598 pins the value against the host's Node.
@vercel

vercel Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 11, 2026 3:41am UTC

Comment on lines +1540 to +1541
sscanf(value, "%lld %lld", &limit, &period) == 2 && period != 0)
*quota = limit / period;

@vercel vercel Bot Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cgroup v2 CPU quota rounding down to 0 (sub-1-CPU container limit) is dropped instead of clamped to 1, so os.availableParallelism() diverges from Node/libuv in exactly the containerized case the feature targets.

Fix on Vercel

This branch was successfully deployed

1 active (outdated) deployment
Preview — 9b923f5e Deployed Oct 11, 2026 by vercel[bot]
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.

1 participant