Better handling for caches in skyfunctions
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
We have several caches used currently in skyfunction implementations, with many specifically, used directly or indirectly from `ConfiguredTargetFunction`. Some examples are:
- [`StarlarkTransitionCache`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/config/StarlarkTransitionCache.java?ss=bazel&q=caffeine&start=31)
- [`BuildConfigurationKeyCache`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/producers/BuildConfigurationKeyCache.java?ss=bazel&q=caffeine&start=41)
- [`PlatformMappingValue.parserCache`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingValue.java;drc=0803ad3770155be411a703950502dc71743017bd;l=152?ss=bazel&q=caffeine&start=21)
- [`StarlarkDefinedConfigTransition.ruleTransitionCache`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/config/StarlarkDefinedConfigTransition.java?q=symbol%3A%5Cbcom.google.devtools.build.lib.analysis.config.StarlarkDefinedConfigTransition.ruleTransitionCache%5Cb%20case%3Ayes)
Each of these are used to cache expansive computations that may be repeated multiple times in the same build (ie, in one `bazel build` call). Each of these would ideally also persist from build to build in case the same computation is needed across builds.
We've also seen several classes of error arising from the files used to determine cache values being changed between builds, but the cache not being invalidated:
- https://github.com/bazelbuild/bazel/issues/22995 - Flags from `platform` weren't re-computed when the underlying BUILD file changed
- https://github.com/bazelbuild/bazel/issues/23097 - Transitions weren't re-computed when the underlying bzl file changed.
There may well be more of these.
Contributor guide
Research direction
Start by comparing cache ownership and invalidation in StarlarkTransitionCache.java, BuildConfigurationKeyCache.java, PlatformMappingValue.java, and StarlarkDefinedConfigTransition.java, focusing on uses from ConfiguredTargetFunction. Review issues 22995 and 23097 for failure cases. Done should define a consistent approach for persistence and invalidation across the identified caches, including changes to the underlying files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100