Skip to content

fix: call graph correctness and performance improvements - #7

Merged
bubunyo merged 11 commits into
masterfrom
bug/minor-bugs
Mar 13, 2026
Merged

fix: call graph correctness and performance improvements#7
bubunyo merged 11 commits into
masterfrom
bug/minor-bugs

Conversation

@bubunyo

@bubunyo bubunyo commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Fixes five issues found during evaluation:

  • funcKey collision — methods with the same name on different receiver types in the same package collided to the same key. Now uses fn.String() which is receiver-aware and unique.
  • Exclude patterns — cfg.Exclude.Patterns and SkipVendor were parsed but never applied. Functions from matched files are now removed from the graph, nodes, reverse index, and owner map.
  • Baseline version check — LoadBaseline now rejects baselines whose version doesn't match CurrentVersion, preventing silent wrong diffs from stale snapshots.
  • findSSAFunc O(N²) → O(1) — replaced linear CHA node scan with a ssaIndex map built once in BuildGraph().
  • isService() O(N) → O(1) — replaced per-call owner scan with a serviceSet precomputed in NewAnalyzer().
  • Dead code removed — SourceFileInfo and ImpactIndex in types.go were unused.
    All changes include tests. Full suite passes.

Copilot AI review requested due to automatic review settings March 9, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses five correctness and performance bugs in the buildgraph call graph analyzer:

  • funcKey collision fixfuncKey() now uses fn.String() (which includes the receiver type) instead of pkg.path + "." + fn.Name(), preventing name collisions between methods on different receiver types within the same package.
  • Exclude patterns enforcementapplyExcludeFilters() is introduced to actually apply cfg.Exclude.Patterns and SkipVendor after BuildGraph(), removing matched functions from all graph structures.
  • Baseline version checkLoadBaseline now rejects baselines whose Version does not match CurrentVersion, preventing silent incorrect diffs from stale snapshots.
  • O(N²) → O(1) findSSAFunc — A ssaIndex map is built once in BuildGraph() so findSSAFunc is a constant-time lookup.
  • O(N) → O(1) isService — A serviceSet is precomputed in NewAnalyzer() for O(1) service membership checks.
  • Dead code removed: SourceFileInfo and ImpactIndex types from types.go.

Changes:

  • funcKey bug fix, ssaIndex for O(1) lookups, and applyExcludeFilters implementation
  • serviceSet precomputation in impact.Analyzer
  • CurrentVersion constant and version check in LoadBaseline

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/analyzer/analyzer.go Core changes: funcKey uses fn.String(), builds ssaIndex in BuildGraph(), adds applyExcludeFilters() and fileMatchesExclude()
pkg/analyzer/analyzer_test.go Tests for funcKey collision fix and exclude patterns
pkg/analyzer/ssa_index_test.go Tests for ssaIndex O(1) lookup (internal package test)
pkg/impact/impact.go serviceSet precomputed in NewAnalyzer(), isService() simplified to O(1) map lookup
pkg/impact/impact_test.go Tests for serviceSet precomputation
pkg/storage/storage.go Adds CurrentVersion = "1.0" constant; LoadBaseline now validates version
pkg/storage/storage_test.go Tests for version validation in LoadBaseline
pkg/types/types.go Removes unused SourceFileInfo and ImpactIndex types
testproject/core/collision/collision.go New test fixture with (*A).Run and (*B).Run for collision testing
testproject/services/service-a/main.go Updated to call both collision methods to exercise the call graph

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/analyzer/ssa_index_test.go
Comment thread pkg/analyzer/analyzer_test.go Outdated
Comment thread pkg/analyzer/analyzer.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/storage/storage.go
@bubunyo
bubunyo merged commit 5b6f748 into master Mar 13, 2026
5 checks passed
@bubunyo
bubunyo deleted the bug/minor-bugs branch March 13, 2026 06:33
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.

2 participants