bazelbuild/bazel

C++ recompilation is too sensitive to preprocessor-only changes

Open

#18.246 geöffnet am 27. Apr. 2023

Auf GitHub ansehen
 (5 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Java (4.465 Forks)batch import
P3help wantedteam-Rules-CPPtype: feature request

Repository-Metriken

Stars
 (25.384 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 22T 20h) (77 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide