-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(core): use Set for O(1) visited node lookup in hasPath #33754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): use Set for O(1) visited node lookup in hasPath #33754
Conversation
The hasPath function used an array with indexOf() for cycle detection during graph traversal. This is O(n) per lookup, making the overall traversal O(n²) in the worst case. Changed to use Set with has() for O(1) lookups, reducing complexity to O(n) for graph path finding operations.
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
View your CI Pipeline Execution ↗ for commit 7af913e
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nx Cloud has identified a flaky task in your failed CI:
Since the failure was identified as flaky, the solution is to rerun CI. Because this branch comes from a fork, it is not possible for us to push directly, but you can rerun by pushing an empty commit:
git commit --allow-empty -m "chore: trigger rerun"
git push
🎓 Learn more about Self-Healing CI on nx.dev
FrozenPandaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! LGTM 🎉
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
The
hasPathfunction ingraph.tsuses an array withindexOf()for tracking visited nodes during recursive graph traversal:This results in O(n) lookups per node visited, making worst-case traversal O(n²).
Expected Behavior
Use
Setfor O(1) visited node tracking:Performance Impact
Example with 500 nodes:
Why Accept This PR
--focusflag will be significantly faster on large monoreposRelated Issue(s)
Contributes to #32265
Merge Dependencies
This PR has no dependencies and can be merged independently.