Filter toolchains by target platform #10
The core insight here seems to be (correct me if I am wrong) that you can read the constraints directly from the Target without actually doing the full resolution of ConfiguredTargetFunction, and potentially short circuit a lot of work.
This is something I considered a few years ago, but I wasn't sure if the gains were worthwhile. I think you've shown that they are.
My only real suggestion is to add some comments to RegisteredToolchainFunction clarifying what the checks are doing and why.
My biggest concern is whether this is adding new skyframe edges or just re-allocating the ones that existed before this change. This isn't an issue in bazel, but google's internal distributed skyframe is very sensitive to the number of edges as well as the number of nodes, and so could potentially prove a problem there. I believe checking this before and after your change with bazel dump --skyframe=summary should be sufficient.
I'd love to see this merged back to mainline bazel.
katre
zbarsky-openai
Reject native toolchain declarations that cannot match the resolver's
target platform before configuring their target_settings. Follow
unconditional native aliases and use the existing constraint matching
semantics, including defaults. Keep normal analysis for configurable
aliases, malformed constraints, cycles, and declarations that inherit the
target platform's constraints. Debug mode retains all candidates so it
can explain rejections.
As with the existing requested-type filter, validation errors in
irrelevant declarations are deferred until those declarations are
needed. This includes errors in other attributes and alias visibility
or compatibility. The debug path retains eager validation.
Three baseline and three candidate full --nobuild runs, with identical
source/flags, warm repositories, fresh servers and a 56 GiB heap cap,
measured these medians:
| Metric | Before | After |
| --- | ---: | ---: |
| Configured targets | 8,388,497 | 5,494,561 |
| Analysis time | 217.567 s | 194.326 s |
| Wall time | 259.402 s | 233.876 s |
| Retained heap | 27,406 MB | 24,573 MB |
Configured targets fell 34.5%, analysis time 10.7%, and retained heap
10.3%. Peak RSS was essentially unchanged. Individual analysis samples
were [222.022, 217.567, 215.736] s before and
[196.611, 194.326, 193.475] s after. Target counts were stable in every
repeat. Created actions (7,751,549), retained actions (7,741,504), and
output artifacts (9,231,190) were unchanged.
The benchmark used the release-20 source at
1fd51d36c59ad0e765df05b465b0e2209801f167 with identical diagnostic code in
both binaries. All six runs selected the same 117,710 targets, analyzed
the same 117,625, and encountered the same 85 pre-existing failures.
These were comparable partial analyses, not successful builds.
All 84 executed cases passed across RegisteredToolchainsFunctionTest,
SingleToolchainResolutionFunctionTest, ToolchainsForTargetsTest and
ToolchainResolutionFunctionTest. A native Python extension test passed.
Normalized runtime action comparisons matched on Linux x86_64, Linux
ARM64 and macOS ARM64; normalization removed only configuration hashes
from output paths and compared arguments, environment, inputs, outputs,
parameter files, execution platform, and action multiplicities.