Zig build not using all the cores

Hello everyone,

I noticed that when I try to build a project, only one core is being used in my laptop. I’m using zig version 0.14.0-dev.2851+b074fb7dd and just tried building zls master branch and I got this CPU usage during the build:

I get the same results if I switch to the 0.13.0 zig version and try to build the 0.13.0 version on zls.

Could someone help me to solve this issue? Thanks.

Current Zig incremental/multithread compilation (not available in .13) is opt-in under a command-line option, because it is WIP.

To be clear the Zig compiler pipeline is multithreaded in various ways. For example:

  • All of the AstGen phase of the pipeline is fully dispatched per-file.
  • All the C objects that need to be compiled happen on the thread pool.
  • Any libc artifacts are created by a worker from the thread pool.
  • Some backends have been refactored to support “separate codegen thread” which means semantic analysis and codegen happen simultaneously.
  • Any build.zig steps that can be run simultaneously will be.

However there is a bottleneck in semantic analysis of the compiler. Only one thread at a time can work on semantic analysis, across all of the Zig code in a given compilation. One goal for the future will be to introduce parallelism into this component as well.

10 Likes