Skip to content

Avoid recomputing dataflow for constructors and initializers - #2079

Merged
msridhar merged 2 commits into
uber:masterfrom
agrieve:fix-cfg-cache-treepath-identity
Oct 27, 2026
Merged

msridhar merged 2 commits into
uber:masterfrom
agrieve:fix-cfg-cache-treepath-identity

Conversation

@agrieve

@agrieve agrieve commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

DataFlow's CFG cache is keyed by CfgParams, whose equality compared TreePaths. 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 TreePaths 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.

Summary by CodeRabbit

  • Improvements
    • Analysis now compares constructor and initializer paths based on the identity of their underlying code element, while other paths continue to use full path comparisons.
    • As a result, analysis results for constructors and initializers may be grouped differently.

`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.
@cla-assistant

cla-assistant Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between bc30c7d and a6d6043.

Files selected for processing: 1
  • nullaway/src/main/java/com/uber/nullaway/dataflow/DataFlow.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

CfgParams now compares constructor and initializer paths by leaf identity. It continues to compare other paths with TreePath.equals. Its hashCode uses the identity hash of the path leaf. The documentation describes these comparison rules.

Possibly related issues

Suggested reviewers: rishikraj990

Priority: Low

Change: Refactor

Merge Risk: Minimal · up to a6d60

No actionable merge-blocking risk is identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing repeated dataflow analysis for constructors and initializers.
Description check Passed The description directly explains the CFG cache issue, the identity-based comparison change, the scope of the behavior, and the reported performance impact.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@msridhar

Copy link
Copy Markdown
Collaborator

Thanks, @agrieve! We will need the CLA to be signed in order to accept this change.

@agrieve

agrieve commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Signed :)

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.20%. Comparing base (3c4cd94) to head (a6d6043).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...main/java/com/uber/nullaway/dataflow/DataFlow.java 87.50% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msridhar

Copy link
Copy Markdown
Collaborator

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.

@msridhar

Copy link
Copy Markdown
Collaborator

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!

@msridhar
msridhar added this pull request to the merge queue Oct 27, 2026
Merged via the queue into uber:master with commit fd537d1 Oct 27, 2026
37 of 39 checks passed
mernst pushed a commit to mernst/NullAway that referenced this pull request Nov 12, 2026
…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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants