HeadlinesBriefing favicon HeadlinesBriefing.com

Bun Adds cgroup-aware CPU Core Detection on Linux

Hacker News •
×

Bun's JavaScript runtime now reports accurate CPU core counts in containerized environments through a significant Linux-specific enhancement. The change routes navigator.hardwareConcurrency and os.availableParallelism() through WTF::numberOfProcessorCores() instead of direct sysconf/sysctl calls. This modification ensures containers with CPU limits via --cpus=N correctly report N cores rather than the host machine's total core count.

Previously, JavaScript applications running in Linux containers would see the host system's full CPU count, leading to resource over-allocation and inefficient thread spawning. The new implementation leverages Linux's sched_getaffinity combined with cgroup cpu.max capping within the WTF (Web Template Framework) layer. This approach aligns Bun's behavior with modern container orchestration practices where CPU constraints are common.

This technical improvement matters because accurate CPU detection directly impacts performance optimization in Node.js and Bun environments. Developers can now write more efficient parallel processing code without manual CPU count adjustments for containerized deployments. The change represents Bun's commitment to container-first development, addressing a long-standing pain point for teams running JavaScript applications in Kubernetes, Docker, or other container platforms.