-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to achieve better build performance? #85
Comments
Thank you very much for your detailed report. The first thing that comes to my mind after reading it is that the host compiler won't use the sysroot of this repo. The sysroot by itself is more than 7k tiny files, so there's an extra cost to setup the sandbox for them, which I believe you captured well in your debugging. The only thing I can do on our side (other than suggest |
From a |
Another thing we can do is to ditch the bootlin files completely and rely on the binaries we already build to create the sysroots. I have some work in progress for this locally already. |
Ultimately it's the same Bazel problem as the nodejs ecosystem has reported for a long time, where thousands of inputs are slow to sandbox. bazelbuild/bazel#8230 is one issue I've followed. It feels to me like the ideal solution would be for tools like gcc and clang to be able to use an archive file as a sysroot, then read inside that archive as a virtual filesystem. That decreases it to a single input from Bazel's perspective. Another option here is to turn off sandboxing for the typical developer workflow, and do something less frequent to ensure that all srcs/deps are actually declared. |
Thanks for the detailed comments! I appreciate that.
I think this sounds great because projects that build LLVM from source with Bazel can benefit from that. But I'm not sure how much effort is needed to implement the functionality inside Bazel. It seems FUSE is necessary to implement that. |
By the way, when I built the same target with
|
Using |
Created that linked issue to see if someone from the Bazel team can explain why sandbox reuse is still experimental. |
@f0rmiga Thanks for the explanation. That really makes sense to me. I agree using '--experimental_reuse_sandbox_directories'. |
@alexeagle Thanks for creating the issue! |
According to bazelbuild/bazel#16138 (comment), @tetsuok please reopen if you want to discuss any further. |
It seems build performance needs to be improved compared to the build performance using the host compiler. I realized the issue in a x86-64 Linux VM on GCP when I built C++ libraries (e.g., protobuf, gRPC) with this toolchain. It seems the build using gcc-toolchain takes longer than when building C++ libraries using the host compiler. The reason seems to be costs for sandbox setup and deletion for every compile action, as far as I investigated. I noticed this performance issue can be mitigated by adding the
--experimental_reuse_sandbox_directories
option to CLI or.bazelrc
. Since that option is experimental, I'm wondering there is any way to improve the build performance using gcc-toolchain.For the record, below is the result of performance profiling on that VM. I measured the build time of the
//examples/protobuf:hello_world_proto
target in this repo in three different settings:--action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
,--incompatible_strict_action_env=true
,--incompatible_enable_cc_toolchain_resolution
in.bazelrc
)--experimental_reuse_sandbox_directories
in.bazelrc
.Environment Information
$ uname -a Linux ubuntu-0 5.15.0-1016-gcp #21~20.04.1-Ubuntu SMP Fri Aug 5 12:53:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:hsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1) $ bazel version Build label: 5.2.0 Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Tue Jun 7 16:02:26 2022 (1654617746) Build timestamp: 1654617746 Build timestamp as int: 1654617746
Repro steps
Results
The following table shows the outputs of the above
bazel analyze-profile /tmp/prof
command for three settings. Here are few observations:Tracing
Analyzed collected files by
bazel analyze-profile
inchrome://tracing
for each setting, following https://bazel.build/rules/performance. The following screenshots show the results (execution phase) of gcc-toolchain and gcc-toolchain w/ reuse sandbox, respectively (corrected order of the screenshots).Observations
The text was updated successfully, but these errors were encountered: