From 9015cd7dc4366a23e5406c79096fb655000ba055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 21 Nov 2022 06:56:12 +0200 Subject: [PATCH] use `bazel build --batch` --- .build.yml | 8 ++++---- README.md | 33 +++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.build.yml b/.build.yml index 87723bf..171a94e 100644 --- a/.build.yml +++ b/.build.yml @@ -14,13 +14,13 @@ tasks: sudo apt-get purge gcc -y && sudo apt-get autoremove -y - llvm14: | cd test-zigcc; . .envrc - bazel clean; bazel shutdown; bazel build --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux ... + bazel clean; bazel --batch build --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux ... - zig_cc-no_sandbox: | cd test-zigcc; . .envrc - bazel clean; bazel shutdown; bazel build --spawn_strategy=local --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... + bazel clean; bazel --batch build --spawn_strategy=local --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... - zig_cc-devshm: | cd test-zigcc; . .envrc - bazel clean; bazel shutdown; bazel build --sandbox_base=/dev/shm --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... + bazel clean; bazel --batch build --sandbox_base=/dev/shm --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... - zig_cc-plain: | cd test-zigcc; . .envrc - bazel clean; bazel shutdown; bazel build --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... + bazel clean; bazel --batch build --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... diff --git a/README.md b/README.md index a835081..ac3ea25 100644 --- a/README.md +++ b/README.md @@ -4,33 +4,46 @@ bazel-zig-cc and llvm bazel-zig-cc has a performance issue when compiling many files. This repository reproduces that. +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. + Steps to reproduce ------------------ -llvm14: 12-13 seconds to compile 64 binaries on an 8-core machine: +Baseline is llvm14: 12-13 seconds: ``` -$ bazel clean; bazel shutdown; bazel build --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux ... +$ bazel clean; bazel --batch build --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux ... INFO: Elapsed time: 12.454s, Critical Path: 1.11s ``` -zig cc: 142 seconds: +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: ``` -$ bazel clean; bazel shutdown; bazel build --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... -INFO: Elapsed time: 142.264s, Critical Path: 20.65s +bazel clean; bazel --batch build --spawn_strategy=local --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... +INFO: Elapsed time: 17.021s, Critical Path: 1.67s ``` -zig cc with `--sandbox_base=/dev/shm`: 40 seconds: +zig cc with `--sandbox_base=/dev/shm`: all sandbox files, including the +zig_sdk, are put to `/dev/shm`. However, they are all symlinks, which means zig +will re-hash all it's dependencies. 42 seconds: ``` -bazel clean; bazel shutdown; bazel build --sandbox_base=/dev/shm --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... +bazel clean; bazel --batch build --sandbox_base=/dev/shm --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... INFO: Elapsed time: 42.251s, Critical Path: 5.26s ``` -zig cc without the sandbox (which means zig will treat its dependencies as the same file): 17 seconds: +zig cc plain: 142 seconds. Sandbox is on a real disk, which means it will take +even longer to re-hash all its dependencies: ``` -bazel clean; bazel shutdown; bazel build --spawn_strategy=local --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... -INFO: Elapsed time: 17.021s, Critical Path: 1.67s +$ bazel clean; bazel --batch build --platforms=@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.28 ... +INFO: Elapsed time: 142.264s, Critical Path: 20.65s ``` + +[1]: https://sr.ht/~motiejus/bazel-zig-cc +[2]: https://github.com/grailbio/bazel-toolchain