C++ recompilation is too sensitive to preprocessor-only changes
#18,246 创建于 2023年4月27日
仓库指标
- Star
- (25,384 star)
- PR 合并指标
- (平均合并 22天 20小时) (30 天内合并 77 个 PR)
描述
Description of the feature request:
Whenever there is a preprocessor-only change to the build graph (say a new -I flag added to the compiles), Bazel will invalidate all C++ actions and recompile all of them. This can be very costly.
ccache has logic to mitigate this problem by splitting a single C++ compile into its preprocessing step and its compilation step. These two steps are then cached separately, so that if the preprocessing of a file does not result in a different output, the recompilation is skipped. For an individual action, the performance impact may be small, but the key here is that this can have cascading effects on the build graph.
It'd be nice if the C++ rules in Bazel offered similar functionality and ran the preprocessor and the compiler as separately-cacheable actions. The C++ compiler is going to run the two stages separately anyway, so Bazel could do it too.
As a workaround, it's possible to use ccache in combination with Bazel to obtain the desired behavior, but this sounds like a hack. It'd be great to evaluate whether Bazel wants to do this on its own or not, and if not, recommend how to set up ccache in a way that works well with dynamic execution.
What underlying problem are you trying to solve with this feature?
Faster build performance when there are innocuous changes deep in the dependency chain that have minimal impact on the majority of the build graph. This is common when doing a git rebase for example.
Which operating system are you running Bazel on?
N/A
What is the output of bazel info release?
bazel-6.1.1
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
No response
What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response