[RFQ] Content hashes at home#9738
[RFQ] Content hashes at home#9738oharboe wants to merge 3 commits intoThe-OpenROAD-Project:masterfrom
Conversation
|
@hzeller Thoughts? |
|
clang-tidy review says "All clean, LGTM! 👍" |
There was a problem hiding this comment.
Code Review
This pull request introduces ccache support to improve local build times, which is a valuable enhancement for developer productivity. The implementation via a patch to toolchains_llvm and a new Bazel configuration is well-executed. The included refactoring of genrules to more specific bazel_skylib rules is also a good cleanup. I have one suggestion to make the ccache integration more robust for users with customized environments.
|
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
|
clang-tidy review says "All clean, LGTM! 👍" |
|
I always comment out the llvm toolchain, so I don't know what it does. But usually bazel does employ some content-based hashing, but @QuantamHD might know more. One problem we have is that we have currently have super coarse grained libraries due to the historic way OpenROAD is compiled, so many files are compiled into one library instead have having many small libraries. So if any of the files in these change, the compilation that builds that probably has to rebuild all as they use these param files (don't know exactly). Anyway, if ccache works for you, you should use it. Longer term, we should structure the project to be more fine-grained. |
|
The idea is to have ccache mitigate the coarse grained libraries. |
This comment was marked as outdated.
This comment was marked as outdated.
If headers change you should recompile. Flags change rarely. How often do you encounter this? It's never been a pain point for me. |
I find myself recompiling all the time. |
Yesterday we reduced the workers disk from 500GB to 100GB to allow more workers with the same resources. |
Patch toolchains_llvm cc_wrapper.sh to use ccache if installed. Falls through to plain clang when ccache is absent. Tested: after bazel clean --expunge and removing ~/.cache/bazel-disk-cache, bazel build --config=ccache //src/drt rebuilt with 1339/1339 (100%) ccache direct hits in 3m49s. A trivial comment change to MakeTritonRoute.cpp produced exactly 1 ccache miss + 1338 hits, confirming ccache correctly detects changed preprocessed content. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Apply ccache integration to the toolchains_llvm osx_cc_wrapper template, matching the Linux cc_wrapper ccache support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
I have not studied disk usage. |
|
clang-tidy review says "All clean, LGTM! 👍" |
|
I think this is not a good solution, and a better solution would be to break up the existing coarse grained targets into fine grained rules rather than mask this problem with another layer of caching. |
Makes sense to me if we can have it in some reasonable amount of time. This could be a stopgap. I have an experiment to measure the benefit of this, which is interesting information, regardless of solution. |
Benchmark measuring ccache benefit for typical developer workflows (single-tool fix, algorithm improvement, cross-cutting refactor). Results show 10x speedup across all scenarios with 100% cache hit rate after `bazel clean`, reducing rebuild from ~25 min to ~2.5 min. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
@QuantamHD @hzeller @maliberty Fantastic if it is true: 10x faster while we wait for bazel migration to complete at which point we can retire this. Unless bazel grows this feature and we can also retire this. |
|
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
|
clang-tidy review says "All clean, LGTM! 👍" |
|
@maliberty @hzeller @QuantamHD Killer use-ase: caching across git work trees... OpenROAD Build Optimization: ccache Integration (PR #9738)Executive SummaryPull Request #9738 introduces ccache support into the OpenROAD Bazel build system. While Bazel has a built-in action cache, it is often invalidated by common developer workflows (switching branches, editing The Problem: Why Bazel Cache Isn't EnoughBazel's native cache is "fragile" in local development because it is keyed on the Action Graph. If any of the following change, Bazel may force a recompile even if the
The Solution: How ccache Helps
[Image of ccache architecture showing how it intercepts compiler calls and interacts with the cache] Key Use Case: Cross-Worktree & Branch CachingThe most significant benefit of this PR is for developers managing multiple tasks:
|
ccache Performance Benchmark for OpenROAD Bazel Build
Why ccache?
Bazel's built-in action cache is keyed on the action graph (flags, BUILD files,
dependency versions), not on source-file contents. Common developer workflows
-- switching branches, editing a BUILD file, or running
bazel clean-- invalidatethe action cache even when most source files are unchanged.
ccachecaches based on preprocessed source content, so it survives theseinvalidations and delivers near-instant cache hits for unchanged translation units.
Environment
82027a28d3Developer Personas (from git history)
We analyzed the last 500 commits to identify typical developer workflows:
Methodology
--config=ccacheto warm ccache (all 83 cc_library targets)a. Append a unique comment to the scenario's source files (real content change, not just
touch)b.
bazel cleanto invalidate Bazel's action cachec. Rebuild with ccache -- record wall-clock time and hit rate
d. Restore files via
git checkoute. Re-apply same edits,
bazel cleanagainf. Rebuild without ccache (
CCACHE_DISABLE=1) -- record wall-clock timeg. Restore files
--disk_cache= --remote_cache=) to isolate ccache effectResults
Key Findings
to ~2.5 minutes after
bazel clean.across 5 modules achieves full hits because Bazel recompiles all targets after
bazel clean, but ccache recognizes unchanged preprocessed content.rebuild time because ccache serves all unchanged translation units from cache.
The small increase from 143s to 154s reflects the additional files that must be
genuinely recompiled.
and results are reliable.
When does this help?
Any workflow that invalidates Bazel's action cache while leaving most source unchanged:
bazel clean-- full action cache wipe, but ccache still has all objects-c optvs-c dbgetc.Setup
Add to your
user.bazelrc:Or invoke explicitly:
Reproducing
The benchmark script is at
tools/ccache_benchmark.sh: