Optimize --changed-dependents=transitive when filter is specified#23224
Open
jasonwbarnett wants to merge 1 commit intopantsbuild:mainfrom
Open
Optimize --changed-dependents=transitive when filter is specified#23224jasonwbarnett wants to merge 1 commit intopantsbuild:mainfrom
jasonwbarnett wants to merge 1 commit intopantsbuild:mainfrom
Conversation
When using --changed-since with --changed-dependents=transitive AND a target filter (--tag, --filter-target-type), the current implementation builds the full reverse dependency graph for ALL targets in the repo via map_addresses_to_dependents(). This requires resolving dependencies (including Python import inference) for every single target, which is very slow in large repos (52K+ targets). This commit adds an optimized code path that inverts the approach: instead of building the full reverse graph, it performs a forward BFS from only the targets matching the filter, builds a restricted reverse dependency map from just the visited subgraph, then walks from the changed owners to find which filtered targets are affected. For a monorepo with ~53K targets and ~2,800 matching test targets, this reduces the number of targets requiring dependency resolution from 53K to ~24K (the forward closure of test targets), yielding a ~26% speedup in wall-clock time. The optimization only activates when specs_filter.is_specified AND dependents == TRANSITIVE. All other code paths are unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 8, 2026
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.
Summary
Optimizes
--changed-sincewith--changed-dependents=transitivewhen a target filter (--tag,--filter-target-type) is also specified.The current implementation builds the full reverse dependency graph for ALL targets in the repo via
map_addresses_to_dependents(). This requires resolving dependencies (including Python import inference) for every single target, which is very slow in large repos (52K+ targets).Approach
When
specs_filter.is_specifiedanddependents == TRANSITIVE, we invert the approach:AllUnexpandedTargetsto find targets matching the filter (e.g.,python_testtargets without theintegrationtag)This skips dependency resolution for targets unreachable from the filtered set (Docker, Helm, Shell targets, etc. when filtering for
python_test).Results
Tested on a monorepo with ~53K targets and ~2,800 matching test targets:
changed_integration_test.pypassspecs_filter.is_specifiedANDdependents == TRANSITIVE; all other code paths unchangedContext
This addresses the same performance issue as the experimental branch
ts/try-faster-filter-dependents, but with a different strategy:TransitiveTargetsRequestper matched target (N separate BFS walks)Related: #15544
🤖 Generated with Claude Code