fix(snap-distance): convert recursive traversal to iterative to prevent stack overflow#10144
Merged
davidfirst merged 2 commits intomasterfrom Jan 5, 2026
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
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()andarray.find()checks toSet.has()for tracking processed versions - Removes dependency on
pMapSeriesfor 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.
GiladShoham
approved these changes
Jan 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Set<string>for O(1) duplicate detection instead of array lookupsChanges
getSubsetOfVersionParents: recursive → iterative with stackgetAllVersionsInfo: recursive → iterative with queuegetAllHashesFrom: recursive → iterative with stack