Skip to content

fix(snap-distance): convert recursive traversal to iterative to prevent stack overflow#10144

Merged
davidfirst merged 2 commits intomasterfrom
fix/stack-overflow-deep-version-history
Jan 5, 2026
Merged

fix(snap-distance): convert recursive traversal to iterative to prevent stack overflow#10144
davidfirst merged 2 commits intomasterfrom
fix/stack-overflow-deep-version-history

Conversation

@davidfirst
Copy link
Copy Markdown
Member

Summary

  • Convert recursive version history traversal to iterative approach using explicit stacks/queues
  • Fixes "Maximum call stack size exceeded" error on repositories with deep version histories (2000+ versions)
  • Also improves performance by using Set<string> for O(1) duplicate detection instead of array lookups

Changes

  • getSubsetOfVersionParents: recursive → iterative with stack
  • getAllVersionsInfo: recursive → iterative with queue
  • getAllHashesFrom: recursive → iterative with stack

…nt stack overflow

Replace recursive version history traversal with iterative approach using
explicit stacks/queues to handle repositories with deep version histories
(2000+ versions) without exceeding the call stack limit.
Copilot AI review requested due to automatic review settings January 5, 2026 15:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request converts three recursive version history traversal functions to iterative implementations to prevent stack overflow errors on repositories with deep version histories (2000+ versions). The changes also improve performance by using Set<string> for O(1) duplicate detection instead of array-based lookups.

Key changes:

  • Replaces recursive calls with explicit stack/queue-based traversal
  • Switches from array.includes() and array.find() checks to Set.has() for tracking processed versions
  • Removes dependency on pMapSeries for one of the async traversal functions

Reviewed changes

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

File Description
scopes/scope/objects/models/version-history.ts Converts getAllHashesFrom from recursive to iterative stack-based traversal with Set for duplicate detection
scopes/component/snap-distance/traverse-versions.ts Converts getAllVersionsInfo from recursive with pMapSeries to queue-based traversal, and getSubsetOfVersionParents from recursive to stack-based traversal, both using Sets for tracking processed hashes

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

@davidfirst davidfirst enabled auto-merge (squash) January 5, 2026 15:50
@davidfirst davidfirst merged commit dadfa17 into master Jan 5, 2026
12 checks passed
@davidfirst davidfirst deleted the fix/stack-overflow-deep-version-history branch January 5, 2026 16:29
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.

3 participants