2022-10-19 11:35:55 +03:00
|
|
|
bazel-zig-cc and llvm
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
bazel-zig-cc has a performance issue when compiling many files. This repository
|
|
|
|
reproduces that.
|
|
|
|
|
2022-11-21 06:56:12 +02:00
|
|
|
The test
|
|
|
|
--------
|
|
|
|
|
|
|
|
Compiles 64 small binaries with [bazel-zig-cc][1] and [llvm14][2]. The tests
|
|
|
|
were run on an x86_64 8-core machine running Ubuntu 22.04.
|
|
|
|
|
2022-10-19 11:35:55 +03:00
|
|
|
Steps to reproduce
|
|
|
|
------------------
|
|
|
|
|
2022-11-21 06:56:12 +02:00
|
|
|
Baseline is llvm14: 12-13 seconds:
|
2022-10-19 11:35:55 +03:00
|
|
|
|
|
|
|
```
|
2022-11-29 16:17:00 +02:00
|
|
|
bazel --batch clean; bazel --batch build --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux ...
|
2022-11-21 06:25:58 +02:00
|
|
|
INFO: Elapsed time: 12.454s, Critical Path: 1.11s
|
2022-10-19 11:35:55 +03:00
|
|
|
```
|
|
|
|
|
2022-11-21 06:56:12 +02:00
|
|
|
zig cc without the sandbox. Which means different invocations of `zig cc` will
|
|
|
|
see that all files in `zig_lib_dir` are the same file. 17 seconds:
|
2022-10-19 11:35:55 +03:00
|
|
|
|
|
|
|
```
|
2022-11-29 16:17:00 +02:00
|
|
|
bazel --batch clean; bazel --batch build --spawn_strategy=local --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ...
|
2022-11-21 06:56:12 +02:00
|
|
|
INFO: Elapsed time: 17.021s, Critical Path: 1.67s
|
2022-11-21 06:37:34 +02:00
|
|
|
```
|
|
|
|
|
2022-12-11 15:55:21 +02:00
|
|
|
zig cc plain: 61 seconds. Sandbox is on a real disk, which means it will take
|
|
|
|
even longer to re-hash all its dependencies:
|
2022-11-21 06:37:34 +02:00
|
|
|
|
|
|
|
```
|
2022-12-11 15:55:21 +02:00
|
|
|
bazel --batch clean; bazel --batch build --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ...
|
|
|
|
INFO: Elapsed time: 61.128s, Critical Path: 8.35s
|
2022-11-21 06:37:34 +02:00
|
|
|
```
|
|
|
|
|
2022-12-11 15:55:21 +02:00
|
|
|
zig cc with hardlinks: `--config=hermetic-sandbox`. This uses hardlinks to
|
|
|
|
zig_sdk instead of symlinks:
|
2022-11-21 06:37:34 +02:00
|
|
|
|
|
|
|
```
|
2022-12-11 15:55:21 +02:00
|
|
|
bazel --batch clean; bazel --batch build --config=hermetic-sandbox --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ...
|
|
|
|
INFO: Elapsed time: 45.886s, Critical Path: 9.56s
|
2022-10-26 00:00:18 +03:00
|
|
|
```
|
2022-11-21 06:56:12 +02:00
|
|
|
|
2022-12-11 15:55:21 +02:00
|
|
|
llvm with sysroot (this sysroot is about half the size of zig):
|
2022-12-11 07:03:10 +02:00
|
|
|
|
|
|
|
```
|
2022-12-11 15:55:21 +02:00
|
|
|
bazel --batch clean; bazel --batch build --config=hermetic-sandbox --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux ...
|
|
|
|
INFO: Elapsed time: 25.644s, Critical Path: 3.03s
|
2022-12-11 07:03:10 +02:00
|
|
|
```
|
|
|
|
|
2022-12-11 15:55:21 +02:00
|
|
|
Flame graphs and discussion
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
Flame graphs are in results/. As of 2022-12-11 most of the overhead comes from
|
|
|
|
creating and deleting the sandboxes. Time for a new sandboxfs!
|
|
|
|
|
|
|
|
|
2022-11-21 06:56:12 +02:00
|
|
|
[1]: https://sr.ht/~motiejus/bazel-zig-cc
|
|
|
|
[2]: https://github.com/grailbio/bazel-toolchain
|