NOW LET US – AI RAG SaaS Studio TP.HCM
NOW LET US
Digital Product Studio
Back to news
DEV-TOOLS...1 min read

Bun: cgroup-aware AvailableParallelism / HardwareConcurrency on Linux

Share
NOW LET US Article – Bun: cgroup-aware AvailableParallelism / HardwareConcurrency on Linux

Bun has updated its CPU core detection logic on Linux to respect cgroup quotas, preventing performance issues in containerized environments like Docker and Kubernetes.

Conversation

Routes navigator.hardwareConcurrency (and therefore os.availableParallelism()) through WTF::numberOfProcessorCores() instead of an inline sysconf/sysctl. On Linux this picks up the new sched_getaffinity + cgroup cpu.max capping in WTF, so containers with --cpus=N report N instead of the host core count.

Walkthrough

Centralized CPU core detection: added Zig/C++ bindings to expose WTF::numberOfProcessorCores(), replaced platform-specific core-count logic with that call, and updated thread and Node OS CPU initialization to use the new APIs. WebKit prebuilt version hash was updated.

Why

Under docker run --cpus=2 (or k8s resources.limits.cpu), the kernel sets a CFS bandwidth quota rather than a cpuset mask. sysconf and sched_getaffinity both still report the host core count, so on a 96-core host Bun spawns ~96 threads for the thread pool, JSC parallel GC markers, and JIT workers. Those threads exhaust the 200ms/100ms quota in a few ms of wall time and the entire cgroup is descheduled for the rest of the period — sawtooth latency, nr_throttled climbing, GC stalls mid-collection. Node returns 2 here (libuv reads cpu.max); Bun returned 96.

What

WTF::numberOfProcessorCores() (WebKit side, separate PR): on Linux, also consults sched_getaffinity and a new uv_get_constrained_cpu() that parses /proc/self/cgroup, dispatches v1/v2, and for v2 walks the hierarchy taking the tightest ceil(quota/period). Same file now also walks the v2 hierarchy for memory.max (previously read leaf only). Result is cached after first call.

  • ZigGlobalObject.cpp: navigator.hardwareConcurrency uses WTF::numberOfProcessorCores() instead of inline sysctl/sysconf.
  • wtf-bindings.cpp / WTF.zig: expose WTF__numberOfProcessorCores() to Zig.
  • bun.zig: getThreadCount() uses it instead of std.Thread.getCpuCount().

One function now feeds JSC GC/JIT sizing, navigator.hardwareConcurrency, os.availableParallelism(), and Bun's internal thread pool.

© 2026 Now Let Us. All rights reserved.

Source: Hacker News

Advertisement
Ad slot ready: 5887729102

More in this category

NOW LET US Related – Treating pancreatic tumours may have revealed cancer's master switch

dev-tools

Treating pancreatic tumours may have revealed cancer's master switch

A promising new drug called daraxonrasib has shown breakthrough results in treating pancreatic cancer, doubling median survival times. This achievement could pave the way for an entirely new class of cancer treatments.

NOW LET US Related – Leaving Mozilla

dev-tools

Leaving Mozilla

A poignant and candid reflection from a 15-year Mozilla veteran upon their departure. The author highlights the leadership's missteps in trying to emulate tech giants and urges Mozilla to return to its core values: community and uniqueness.

NOW LET US Related – Shepherd's Dog: A Game by the Most Dangerous AI Model

dev-tools

Shepherd's Dog: A Game by the Most Dangerous AI Model

A developer tested Anthropic's latest, supposedly 'too dangerous' AI model by asking it to build a long-held game idea in a single shot. The model succeeded, generating a complete 2,319-line game after a 45-minute reasoning session.

NOW LET US Related – Open source AI must win

dev-tools

Open source AI must win

If artificial intelligence becomes a utility rented only from a few closed institutions, humanity loses its operational freedom. Open-source AI is a vital infrastructure for the future of our digital society.

NOW LET US Related – Statement on US government directive to suspend access to Fable 5 and Mythos 5

dev-tools

Statement on US government directive to suspend access to Fable 5 and Mythos 5

The US government has issued an export control directive forcing Anthropic to suspend all access to its Fable 5 and Mythos 5 models due to national security concerns, a move the AI safety startup strongly disputes.

NOW LET US Related – Electric motors with no rare earths

dev-tools

Electric motors with no rare earths

Renault Group is pioneering the development of electrically excited synchronous motors (EESM) that eliminate the need for rare earth magnets, reducing dependency on global monopolies while driving efficiency and sustainability.

EXPLORE TOPICS

Discover All Categories

Deep dive into the specific technology sectors that matter most to you.