Repository navigation
Reuse cached dependency edges in hash output - #562
Merged
tinder-maxwellelliott merged 3 commits intoOct 25, 2026
Merged
tinder-maxwellelliott merged 3 commits into
tinder-maxwellelliott merged 3 commits into
Conversation
Hash traversal keeps each completed rule in its cache until every parent has visited it. Returning an owned digest cloned every dependency label at insertion and again when an already-visited rule was emitted. A generated file also discarded those copies to record its generator. Share nonempty edge lists while traversing the graph and release the cache before collecting output. The last owner can then move the vector into aggregation. Labels used by multiple configured instances still retain their original ordering and deduplication. Codex for Tamir.
Rule inputs normally reach the output as one sorted list. Moving that list preserves its allocation. Its strict label ordering also proves the labels are unique, avoiding a hash set and an extra string copy for every dependency. Keep the first-seen order when several instances or rewritten configured labels produce an unordered or repeated edge. Codex for Tamir.
The generated-alias regression constructs its graph in memory and can run on Windows. Inserting it above the filesystem hashing test moved that test’s existing Unix guard onto the alias case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After #542, a rule's dependency labels were still copied into both the traversal cache and the final output. A large fan-out makes those copies expensive even though parents only read the cached digest. Share the list until traversal finishes, then move it into the output whenever there's one owner. When a rule has one sorted, unique list, reuse its allocation and skip building a hash set to deduplicate it.
In a release build on macOS ARM64, generating hashes and edges for a synthetic graph with 2.16 million edges took 1.294 s before and 1.093 s after, with median peak RSS falling from 840 MB to 639 MB. Both JSON files were byte-identical in all six runs per revision. This measures the CLI with frozen Bazel replies; it does not measure Bazel query execution.
With #564 as the baseline, this change reduced the same fixture’s median from 0.801 s to 0.678 s and median peak RSS from 658 MB to 477 MB. The hash and edge files matched byte for byte in all 12 counterbalanced runs.
The Rust and CLI tests and formatting check pass. A regression covers a raw rule and generated alias that both need the same cached edge list.
Reproduce the benchmark
Build
bazel build --config=release //:bazel-diffat1f26908and this PR's head. Keep both executables. Save the following asbench.pyin an empty temporary directory and runpython3 bench.py /path/to/before /path/to/afterwith Python 3.11 or later on macOS or Linux. It prints median elapsed seconds, median native maximum RSS (bytes on macOS, KiB on Linux), and the SHA-256 of both output files.Codex for Tamir.