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
|
2022-12-12 09:43:08 +02:00
|
|
|
were run on an x86_64 8-core machine running Ubuntu 22.04. The llvm's sysroot
|
|
|
|
is this:
|
2022-11-21 06:56:12 +02:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
sha256 = "84656a6df544ecef62169cfe3ab6e41bb4346a62d3ba2a045dc5a0a2ecea94a3",
|
|
|
|
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/2202c161310ffde63729f29d27fe7bb24a0bc540/debian_stretch_amd64_sysroot.tar.xz"],
|
2022-10-19 11:35:55 +03:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
... but with extra ~8k files, so the number of files in the sysroot is exactly
|
|
|
|
the same as in zig sdk.
|
2022-10-19 11:35:55 +03:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
Baseline
|
|
|
|
--------
|
|
|
|
|
|
|
|
Baseline llvm14 without sandbox: 12 seconds:
|
|
|
|
|
|
|
|
bazel build --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux //:zigzag-0
|
|
|
|
bazel clean; bazel shutdown
|
|
|
|
bazel --batch build --spawn_strategy=local --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux ...
|
2022-12-13 23:03:32 +02:00
|
|
|
INFO: Elapsed time: 13.268s, Critical Path: 1.19s
|
2022-12-12 09:43:08 +02:00
|
|
|
|
|
|
|
zig cc without the sandbox. 15 seconds:
|
|
|
|
|
|
|
|
bazel build --spawn_strategy=local --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 //:zigzag-0
|
|
|
|
bazel clean; bazel shutdown
|
|
|
|
bazel --batch build --spawn_strategy=local --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ...
|
2022-12-13 23:03:32 +02:00
|
|
|
INFO: Elapsed time: 23.836s, Critical Path: 3.47s
|
2022-12-12 09:43:08 +02:00
|
|
|
|
|
|
|
Cost of Sandbox
|
|
|
|
---------------
|
|
|
|
|
|
|
|
llvm 14:
|
|
|
|
|
|
|
|
bazel build --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux //:zigzag-0
|
|
|
|
bazel clean; bazel shutdown
|
|
|
|
bazel --batch build --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux ...
|
2022-12-13 23:03:32 +02:00
|
|
|
INFO: Elapsed time: 89.776s, Critical Path: 12.01s
|
2022-10-19 11:35:55 +03:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
zig cc:
|
2022-10-19 11:35:55 +03:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
bazel build --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 //:zigzag-0
|
|
|
|
bazel clean; bazel shutdown
|
|
|
|
bazel --batch build --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ...
|
2022-12-13 23:03:32 +02:00
|
|
|
INFO: Elapsed time: 58.919s, Critical Path: 8.38s
|
2022-11-21 06:37:34 +02:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
Possible mitigation: Sandboxfs
|
|
|
|
------------------------------
|
2022-11-21 06:37:34 +02:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
No dice.
|
2022-11-21 06:37:34 +02:00
|
|
|
|
2022-12-12 10:18:42 +02:00
|
|
|
llvm 14: does not build at all:
|
|
|
|
|
|
|
|
$ bazel build --experimental_sandboxfs_path=sandboxfs --experimental_use_sandboxfs --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux //:zigzag-0
|
|
|
|
ERROR: /code/test-zigcc/BUILD:4:14: Compiling main.cc failed: (Exit 5): cc_wrapper.sh failed: error executing command external/llvm_toolchain_with_sysroot/bin/cc_wrapper.sh -U_FORTIFY_SOURCE '--target=x86_64-unknown-linux-gnu' -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -fcolor-diagnostics -Wall ... (remaining 29 arguments skipped)
|
|
|
|
|
|
|
|
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
|
|
|
|
ERROR: could not find clang; PWD="/proc/self/cwd"; PATH="<...>".
|
|
|
|
Target //:zigzag-0 failed to build
|
|
|
|
Use --verbose_failures to see the command lines of failed build steps.
|
|
|
|
INFO: Elapsed time: 7.578s, Critical Path: 0.26s
|
|
|
|
INFO: 3 processes: 3 internal.
|
|
|
|
FAILED: Build did NOT complete successfully
|
2022-11-21 06:37:34 +02:00
|
|
|
|
2022-11-21 06:56:12 +02:00
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
zig cc:
|
|
|
|
|
2022-12-12 10:18:42 +02:00
|
|
|
bazel build --experimental_sandboxfs_path=sandboxfs --experimental_use_sandboxfs --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 //:zigzag-0
|
2022-12-12 09:43:08 +02:00
|
|
|
bazel clean; bazel shutdown
|
2022-12-12 10:18:42 +02:00
|
|
|
bazel --batch build --experimental_sandboxfs_path=sandboxfs --experimental_use_sandboxfs --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ...
|
|
|
|
INFO: Elapsed time: 126.613s, Critical Path: 17.63s
|
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
|
|
|
|
Possible mitigation: `--experimental_reuse_sandbox_directories`
|
|
|
|
---------------------------------------------------------------
|
|
|
|
|
|
|
|
Dice.
|
|
|
|
|
|
|
|
llvm 14:
|
|
|
|
|
|
|
|
bazel build --experimental_reuse_sandbox_directories --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux //:zigzag-0
|
|
|
|
bazel clean; bazel shutdown
|
|
|
|
bazel --batch build --experimental_reuse_sandbox_directories --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux ...
|
2022-12-13 23:03:32 +02:00
|
|
|
INFO: Elapsed time: 18.335s, Critical Path: 2.00s
|
2022-12-12 09:43:08 +02:00
|
|
|
|
|
|
|
zig cc:
|
|
|
|
|
|
|
|
bazel build --experimental_reuse_sandbox_directories --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 //:zigzag-0
|
|
|
|
bazel clean; bazel shutdown
|
|
|
|
bazel --batch build --experimental_reuse_sandbox_directories --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ...
|
2022-12-13 23:03:32 +02:00
|
|
|
INFO: Elapsed time: 34.777s, Critical Path: 4.71s
|
2022-12-11 07:03:10 +02:00
|
|
|
|
|
|
|
|
2022-12-11 15:55:21 +02:00
|
|
|
Flame graphs and discussion
|
|
|
|
---------------------------
|
|
|
|
|
2022-12-12 09:43:08 +02:00
|
|
|
Flame graphs and more tests are in results/. As of 2022-12-11 most of the
|
|
|
|
overhead comes from creating and deleting the sandboxes.
|
2022-12-11 15:55:21 +02:00
|
|
|
|
2022-11-21 06:56:12 +02:00
|
|
|
[1]: https://sr.ht/~motiejus/bazel-zig-cc
|
|
|
|
[2]: https://github.com/grailbio/bazel-toolchain
|