Somewhere between 0.16.0-dev.1484+d0ba6642b and 0.16.0-dev.1634+b27bdd5af,
the build system was changed, in particular its scheduling of compilation jobs.
The difference is subtle but noticeable when building C++ projects with hundreds of files.
Previous behavior:
Whenever a file is done compiling, a new file starts compiling, ensuring a near 100% usage of the CPU cores
New behavior
It looks like it waits for all files currently building of a given lib/bin to complete before adding a new job to the queue for that lib/bin.
Said differently
Say it builds libgrpc.so (and to simplify let's say all dependencies were already compiled), on 8 cores. So it starts compiling 8 files in parallel. After some time, one of the 8 files is done compiling.
Previously, it would start compiling a 9th file immediatly.
Now, it waits for the other 7 files to also complete, before enqueuing 8 more files at once.
Impact
Compilation of big (C++ at least) projects takes more time.
$ uname -srm
Darwin 25.3.0 arm64
$ sysctl machdep.cpu
machdep.cpu.cores_per_package: 16
machdep.cpu.core_count: 16
machdep.cpu.logical_per_package: 16
machdep.cpu.thread_count: 16
machdep.cpu.brand_string: Apple M4 Max
I separated the building of the dependencies from the main lib to make the difference more apparent.
The dependencies are 7 C and 1 C++ libs, so when one lib is underusing the CPU, another one is using it, so the impact is mitigated.
Using both zsh builtin time and the time utility
$ zig version
0.15.2
$ time time -hp zig build dependencies
real 29.09
user 151.14
sys 145.08
time -hp zig build dependencies 151.15s user 145.08s system 1017% cpu 29.118 total
$ time time -hp zig build
real 92.08
user 997.57
sys 157.45
time -hp zig build 997.58s user 157.45s system 1254% cpu 1:32.10 total
$ zig version
0.16.0-dev.3153+d6f43caad
$ time time -hp zig build dependencies
real 26.95
user 169.00
sys 64.29
time -hp zig build dependencies 169.01s user 64.30s system 865% cpu 26.960 total
$ time time -hp zig build
real 121.00
user 835.73
sys 73.00
time -hp zig build 835.74s user 73.01s system 750% cpu 2:01.04 total
We can see the build time takes 30% longer with zig master, with a lower CPU usage
The CI jobs of this repo went, on macos, from 9-15 min with zig 0.15.2, to 26-28 min with zig master.
On linux, the impact is a bit smaller, from 20-23 min to 28-31 min
Somewhere between `0.16.0-dev.1484+d0ba6642b` and `0.16.0-dev.1634+b27bdd5af`,
the build system was changed, in particular its scheduling of compilation jobs.
The difference is subtle but noticeable when building C++ projects with hundreds of files.
## Previous behavior:
Whenever a file is done compiling, a new file starts compiling, ensuring a near 100% usage of the CPU cores
## New behavior
It looks like it waits for all files currently building of a given lib/bin to complete before adding a new job to the queue for that lib/bin.
## Said differently
Say it builds `libgrpc.so` (and to simplify let's say all dependencies were already compiled), on 8 cores. So it starts compiling 8 files in parallel. After some time, one of the 8 files is done compiling.
Previously, it would start compiling a 9th file immediatly.
Now, it waits for the other 7 files to also complete, before enqueuing 8 more files at once.
## Impact
Compilation of big (C++ at least) projects takes more time.
## Example with [libgrpc packaged with Zig](https://github.com/allyourcodebase/grpc):
```console
$ uname -srm
Darwin 25.3.0 arm64
$ sysctl machdep.cpu
machdep.cpu.cores_per_package: 16
machdep.cpu.core_count: 16
machdep.cpu.logical_per_package: 16
machdep.cpu.thread_count: 16
machdep.cpu.brand_string: Apple M4 Max
```
I separated the building of the dependencies from the main lib to make the difference more apparent.
The dependencies are 7 C and 1 C++ libs, so when one lib is underusing the CPU, another one is using it, so the impact is mitigated.
Using both zsh builtin `time` and the `time` utility
```console
$ zig version
0.15.2
$ time time -hp zig build dependencies
real 29.09
user 151.14
sys 145.08
time -hp zig build dependencies 151.15s user 145.08s system 1017% cpu 29.118 total
$ time time -hp zig build
real 92.08
user 997.57
sys 157.45
time -hp zig build 997.58s user 157.45s system 1254% cpu 1:32.10 total
```
<img src="/attachments/37478691-c4eb-45ae-bb27-fc0794703b5e" height="200"/>
```console
$ zig version
0.16.0-dev.3153+d6f43caad
$ time time -hp zig build dependencies
real 26.95
user 169.00
sys 64.29
time -hp zig build dependencies 169.01s user 64.30s system 865% cpu 26.960 total
$ time time -hp zig build
real 121.00
user 835.73
sys 73.00
time -hp zig build 835.74s user 73.01s system 750% cpu 2:01.04 total
```
<img src="/attachments/b4609c58-025b-422b-8690-954d466aefb9" height="200"/>
We can see the build time takes 30% longer with zig master, with a lower CPU usage
The CI jobs of this repo went, on macos, from 9-15 min with zig 0.15.2, to 26-28 min with zig master.
On linux, the impact is a bit smaller, from 20-23 min to 28-31 min