Skip to content

Precompute reverse dependency graph for diff-mode change-impact analysis - #147

Merged
alxxjohn merged 1 commit into
mainfrom
alexj/fix-quadratic-dos-in-change-impact-analysis
Aug 19, 2026
Merged

Precompute reverse dependency graph for diff-mode change-impact analysis#147
alxxjohn merged 1 commit into
mainfrom
alexj/fix-quadratic-dos-in-change-impact-analysis

Conversation

@alxxjohn

Copy link
Copy Markdown
Contributor

Motivation

  • The diff-mode change-impact pass previously rebuilt the reverse dependency adjacency map for each changed module, producing O(C*E) work and repeated allocations where C is changed modules and E is import edges.
  • This exposed an algorithmic DoS risk when scanning large attacker-controlled diffs.
  • The fix precomputes the reverse graph once per target graph while preserving existing artifact and finding behavior.

Description

  • Add reverseDependencies() to moduleGraph to build a reverse adjacency map[string][]string once after graph construction.
  • Compute reverse := item.graph.reverseDependencies() once per targetModuleGraph in changeImpactFindings and reuse it for all changed files.
  • Change changeImpactEntry to accept reverse map[string][]string and use support.TransitiveDependents(reverse, module) to derive dependents.
  • Preserve existing sampling, thresholding, artifact emission, and finding messages so functionality and outputs remain unchanged.

Testing

  • Ran go test ./internal/codeguard/checks/design ./tests/checks and the targeted tests completed successfully.
  • Ran go test ./... and the full test suite completed successfully.
  • Ran gofmt and git diff --check to ensure formatting and no diff-check issues and they passed.

Codex Task

@alxxjohn
alxxjohn merged commit 5108419 into main Aug 19, 2026
16 checks passed
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.

1 participant