Skip to content

Compute each block's predecessors once in ControlFlowGraph.checkInvariants - #8698

Closed
mernst wants to merge 1 commit into
typetools:masterfrom
mernst:check-invariants-predecessors
Closed

mernst wants to merge 1 commit into
typetools:masterfrom
mernst:check-invariants-predecessors

Conversation

@mernst

@mernst mernst commented Nov 28, 2026

Copy link
Copy Markdown
Member

Land before #8608.

ControlFlowGraph.checkInvariants checks, for each edge, that the successor's predecessors contain the edge's source. It called Block.getPredecessors once per edge, and getPredecessors takes time quadratic in the number of predecessors. A block such as the exceptional exit can have thousands of predecessors, so this was slow on large CFGs. Now checkInvariants computes each block's predecessors once, as a HashSet.

There is no change in behavior. #8608 makes the CFG of manyNestedTryFinallyBlocks in cfgConstructionTest large enough for this to matter.

…iants

Block.getPredecessors takes time quadratic in the number of predecessors, and
checkInvariants called it once per edge into the block.  A block such as the
exceptional exit can have thousands of predecessors.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ControlFlowGraph.checkInvariants now caches each successor block’s predecessor set in an identity-keyed map. Successor validation checks the cached set. The invariant and its failure result remain unchanged.

Suggested reviewers: smillst

Change: Refactor

Merge Risk: Minimal · up to dd11a

This change speeds up the control-flow graph invariant check for blocks with many predecessors, without changing behavior. It does not appear to carry any merge-blocking risk.

Pre-merge checks: Passed 2

Check name Status Explanation
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.
Finishing Touches

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c706f8e and dd11ae5.

Files selected for processing: 1

  • dataflow/src/main/java/org/checkerframework/dataflow/cfg/ControlFlowGraph.java

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

@mernst

mernst commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Superseded by #8701, which makes Block.getPredecessors take linear time. That gives checkInvariants the same speedup as this pull request (47 ms versus 53 ms for a block with 2000 predecessors, versus 14.6 s with neither change), and it also speeds up the production callers of getPredecessors.

@mernst mernst closed this Nov 28, 2026
@mernst
mernst deleted the check-invariants-predecessors branch November 28, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant