-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(js): use Set for O(1) package.json root lookup #33757
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(js): use Set for O(1) package.json root lookup #33757
Conversation
Previously, isPackageJsonAtProjectRoot used Array.find() to check if a file is a package.json at a project root, resulting in O(n) lookup per file where n is number of projects. Now builds a Set of valid package.json paths once at the start, reducing lookup from O(files × projects) to O(files + projects). Also: - Replaced forEach with for...in/of loops - Removed unused isPackageJsonAtProjectRoot function - Removed unused ProjectConfiguration import
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Thank you @adwait1290 please make this the last one for now and give the team chance to review |
|
@JamesHenry will pause for now; let me know what I can do to help get these reviewed. |
|
View your CI Pipeline Execution ↗ for commit 8148d64
☁️ Nx Cloud last updated this comment at |
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 🎉
|
@adwait1290 We're grateful for the contributions, however no team/project is expecting 25 PRs from a single contributor in rapid succession and so rather than adding to a growing list, it makes sense to wait a few days to allow us to work through the existing ones. You can that including yours we have 150+ PRs open that all need to be reviewed and we're working on it |
|
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
In
buildExplicitPackageJsonDependencies, for every file in the project file map, we callisPackageJsonAtProjectRootwhich usesArray.find():This is O(files × projects) complexity.
Expected Behavior
Build a Set of valid package.json paths once, then use O(1) Set lookup:
Performance Impact
Example: With 5,000 files and 200 projects:
Additional Changes
forEachwithfor...in/ofloopsisPackageJsonAtProjectRootfunctionProjectConfigurationimportWhy Accept This PR
Related Issue(s)
Contributes to #32265
Merge Dependencies
This PR has no dependencies and can be merged independently.