Skip to content

perf(npm-lock-graph): use Set accumulators for edge lists#652

Merged
sonukapoor merged 1 commit into
mainfrom
perf/issue-645-graph-construction-set-accumulators
Jun 14, 2026
Merged

perf(npm-lock-graph): use Set accumulators for edge lists#652
sonukapoor merged 1 commit into
mainfrom
perf/issue-645-graph-construction-set-accumulators

Conversation

@sonukapoor

Copy link
Copy Markdown
Collaborator

Replace spread-array accumulation with Set-based accumulators during npm lock graph construction. Reduces graph construction from O(E×V) to O(E).

Before: unique([...(map.get(key) ?? []), newId]) on every edge — O(n) per insert
After: set.add(newId) — O(1) per insert, converted to array once at end

Refs #645

@sonukapoor sonukapoor force-pushed the perf/issue-645-graph-construction-set-accumulators branch from b26be23 to 771068d Compare June 14, 2026 15:31
@sonukapoor sonukapoor force-pushed the perf/issue-645-graph-construction-set-accumulators branch from 771068d to 60aa7ef Compare June 14, 2026 15:33
@sonukapoor sonukapoor merged commit d3431b1 into main Jun 14, 2026
6 checks passed
@sonukapoor sonukapoor deleted the perf/issue-645-graph-construction-set-accumulators branch June 14, 2026 15:35
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