Repository navigation
Avoid recomputing dataflow for constructors and initializers - #2079
Conversation
`DataFlow`'s CFG cache is keyed by `CfgParams`, whose equality compared `TreePath`s. `TreePath` does not override `equals()`, so lookups only hit when the exact same `TreePath` instance was used. The field initialization checks (`checkFieldInitialization()` and friends) construct new `TreePath`s for constructors, initializer blocks and initializer methods (e.g. `new TreePath(state.getPath(), constructor)`). When the scanner later visits the bodies of the same constructors and initializers, it queries the cache with different `TreePath` instances, so the CFG is rebuilt and the dataflow analysis is re-run from scratch. This change compares constructors, initializer blocks and field initializers by the identity of their leaf trees. Other code is still compared by path identity, since the results for lambdas and anonymous class methods (e.g. in stream chains) can depend on facts recorded by handlers while analyzing other code. On Chromium's chrome_java target (~1900 files, JSpecify mode), this removed ~6% of all CFG constructions and dataflow runs (1,246 of 20,012), and reduced the time spent in NullAway by ~3.5%, with identical diagnostics.
|
No actionable comments were generated in the recent review.
|
|
Thanks, @agrieve! We will need the CLA to be signed in order to accept this change. |
|
Signed :) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2079 +/- ##
=========================================
Coverage 89.20% 89.20%
Complexity 38 38
=========================================
Files 119 119
Lines 12764 12771 +7
Branches 2588 2592 +4
=========================================
+ Hits 11386 11393 +7
+ Misses 622 621 -1
- Partials 756 757 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
LGTM, thanks!! I just want to run our benchmarks to see if they show any difference, but in any case will land this one after. |
|
The benchmark runs didn't show quite as much improvement for any of our benchmarks, but still this is a good improvement and seems to matter more for other code bases. Thanks again! |
…es (uber#2138) Several NullAway slowdowns and stack overflows share one shape: work whose cost grows with the checked code, repeated once per lookup, nesting level, or link of a call chain (uber#1327, uber#1896, uber#2079, uber#2093), or recursion that comes back to a question already in progress (uber#1760, uber#1842, uber#2090). AGENTS.md said nothing about it, so a coding or reviewing agent had no reason to look for either. The new Performance section states the rule and what a fix owes: a timeout or a count of the repeated work, a stack overflow for a cycle, and a test that shows a new cache or cycle guard hits. Whether a dataflow run is reused depends on the key of `DataFlow.CfgParams` (by leaf for constructors and initializers, by `TreePath` identity otherwise, see [`CfgParams.equals`](https://github.com/uber/NullAway/blob/c7732521fc6d4b23ef9efcc87a2ec49171080906/nullaway/src/main/java/com/uber/nullaway/dataflow/DataFlow.java#L436-L463)), so the section spells out which new paths rerun a method or a lambda. Some sites on master already rerun dataflow, some of them on purpose; the section points at uber#2137 for those, so that an agent flags a diff that adds a rerun rather than every diff that passes near an existing one. **Scope.** The section calls uber#2093 still open; that note goes once uber#2095 merges. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Documentation** * Added performance guidance for contributors covering repeated analysis work, rerun conditions, cycle risks, and regression-test expectations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
DataFlow's CFG cache is keyed byCfgParams, whose equality comparedTreePaths.TreePathdoes not overrideequals(), so lookups only hit when the exact sameTreePathinstance was used.The field initialization checks (
checkFieldInitialization()and friends) construct newTreePaths for constructors, initializer blocks and initializer methods (e.g.new TreePath(state.getPath(), constructor)). When the scanner later visits the bodies of the same constructors and initializers, it queries the cache with differentTreePathinstances, so the CFG is rebuilt and the dataflow analysis is re-run from scratch.This change compares constructors, initializer blocks and field initializers by the identity of their leaf trees. Other code is still compared by path identity, since the results for lambdas and anonymous class methods (e.g. in stream chains) can depend on facts recorded by handlers while analyzing other code.
On Chromium's chrome_java target (~1900 files, JSpecify mode), this removed ~6% of all CFG constructions and dataflow runs (1,246 of 20,012), and reduced the time spent in NullAway by ~3.5%, with identical diagnostics.
Summary by CodeRabbit