Fix performance regression with manual trimming.

When --enforce_transitive_configs_for_config_feature_flag=true
(which means manual trimming is enabled), the manual trimming
transition applies to every configured target in the build, even
though it's a no-op for most of them. But it unconditionally creates
new BuildOptions instances, each of which has its hash key computed
later in the build. This is expensive enough to severely harm
analysis time.

With this change, the transition returns the original instance when no
trimming is necessary.

Example results on a trivial android_binary depending on an android_library
with trimming:

Before:
############################################
# Original Blaze, manual trimming disabled:
b/blazedev_orig build --nobuild //testapp:binary --enforce_transitive_configs_for_config_feature_flag=false | sort | uniq -c
137 CALLING BuildOptions.maybeInitializeFingerprintAndHashCode

# Original Blaze, manual trimming enabled:
b/blazedev_orig build --nobuild //testapp:binary --enforce_transitive_configs_for_config_feature_flag=true | sort | uniq -c
809 CALLING BuildOptions.maybeInitializeFingerprintAndHashCode
573 TRIMMING TRANSITION RETURNED NEW BUILDOPTIONS INSTANCE
############################################

After:
############################################
# Updated Blaze, manual trimming disabled:
b/blazedev_new build --nobuild //testapp:binary --enforce_transitive_configs_for_config_feature_flag=false | sort | uniq -c
138 CALLING BuildOptions.maybeInitializeFingerprintAndHashCode

# Updated Blaze, manual trimming enabled:
b/blazedev_new build --nobuild //testapp:binary --enforce_transitive_configs_for_config_feature_flag=true | sort | uniq -c
475 CALLING BuildOptions.maybeInitializeFingerprintAndHashCode
209 TRIMMING TRANSITION RETURNED NEW BUILDOPTIONS INSTANCE
############################################

We still create more instances when manual trimming is on, but this is expected. Note that rules which don't use trimming (don't have the transitive_configs attribute) don't create *any* more instances.

PiperOrigin-RevId: 251520074
2 files changed
tree: e1adc41b1c84e62adf4b608e0b6bc676f9a17660
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEOWNERS
  15. combine_distfiles.py
  16. combine_distfiles_to_tar.sh
  17. compile.sh
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. distdir.bzl
  21. ISSUE_TEMPLATE.md
  22. LICENSE
  23. README.md
  24. WORKSPACE
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel only rebuilds what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Contributing to Bazel

See CONTRIBUTING.md

Build status

Bazel is released in ‘Beta’. See the product roadmap to learn about the path toward a stable 1.0 release.