Skip to content

perf: index vulnerabilities by package and group aliases with union-find - #3097

Closed
ajayk wants to merge 1 commit into
google:mainfrom
ajayk:perf-result-building
Closed

ajayk wants to merge 1 commit into
google:mainfrom
ajayk:perf-result-building

Conversation

@ajayk

@ajayk ajayk commented Sep 18, 2026

Copy link
Copy Markdown

Removes quadratic work when building results and grouping aliases:

  • buildVulnerabilityResults indexes vulnerabilities by package once instead of scanning all vulnerabilities per package.
  • grouper.Group uses union-find over identifiers instead of a pairwise comparison. This also fixes transitive alias chains being split into separate groups when the joining link is discovered late (regression test added).
  • config.Manager.Get memoizes the target path to config path resolution, avoiding a stat syscall per package.
  • Max severity and fix version lookups no longer rescan the vulnerability list per group.

Benchmarks (go test -bench, Apple M-series):

Benchmark Before After
Group/chained/1000 5.20 ms 0.19 ms
Group/isolated/1000 2.63 ms 0.28 ms
BuildVulnerabilityResults/1000pkgs_5vulns 6.0 ms 3.9 ms
BuildVulnerabilityResults/3000pkgs_5vulns 38.9 ms 7.3 ms

Output is unchanged; all snapshot tests pass.

Replace the per-package scan of all vulnerabilities and the pairwise
alias comparison with map-based indexing, memoize config path lookups,
and avoid recomputing severity and fix versions per group.
@G-Rath

G-Rath commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Please read our contributing guide before opening pull requests

@G-Rath G-Rath closed this Sep 18, 2026
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