fix(core): optimize bun lockfile parser#33623
Conversation
Key Optimizations Made 1. Pre-computed PackageIndex - Built once during lockfile parsing: - byName: Map from package name → array of versions (O(1) lookup) - workspaceNames: Set of workspace package names (O(1) lookup) - workspacePaths: Set of workspace paths (O(1) lookup) - packagesWithWorkspaceVariants: Set of packages with workspace-specific variants (O(1) lookup) - patchedPackages: Set of patched package names (O(1) lookup) 2. findResolvedVersion: Changed from O(n) scan through all packages to O(1) map lookup + O(k) where k = number of versions for that package (typically 1-3) 3. isWorkspacePackage: Changed from O(n) scan to O(1) set lookup 4. hasWorkspaceSpecificVariant: Changed from O(n) scan to O(1) set lookup 5. isNestedPackageKey: Now uses pre-computed workspace paths/names sets instead of computing them each call
👷 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.
|
| const prefix = packageKey.substring(0, lastSlash); | ||
|
|
||
| // If the prefix is a workspace path or scoped package pattern | ||
| if (workspacePaths.has(prefix) || prefix.startsWith('@')) { |
There was a problem hiding this comment.
Missing condition in workspace variant detection. The old logic checked prefix.startsWith('@') && prefix.includes('/') but the new code only checks prefix.startsWith('@'). This could incorrectly identify packages as workspace-specific variants.
For example, if a package key is split where the prefix is just @scope (without a slash), it would incorrectly match, whereas the old code would reject it.
Fix:
if (workspacePaths.has(prefix) || (prefix.startsWith('@') && prefix.includes('/'))) {
packagesWithWorkspaceVariants.add(possiblePackageName);
}| if (workspacePaths.has(prefix) || prefix.startsWith('@')) { | |
| if (workspacePaths.has(prefix) || (prefix.startsWith('@') && prefix.includes('/'))) { |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
We fixed two related bugs in the workspace variant detection logic:
Bug 1: buildPackageIndex - Missing condition in workspace variant detection
Location: packages/nx/src/plugins/js/lock-file/bun-parser.ts:492
Problem: The check prefix.startsWith('@') was missing the additional condition
prefix.includes('/'). This could incorrectly identify packages as workspace-specific
variants when the prefix is just @scope (without a slash).
Bug 2: isNestedPackageKey - Scoped packages incorrectly filtered as nested
Location: packages/nx/src/plugins/js/lock-file/bun-parser.ts:1200-1205
Problem: The function's final return true would incorrectly filter legitimate scoped
packages like @types/react or scoped aliases like @custom/lodash as nested packages.
Fix: Added a check before the final return true to recognize simple scoped packages
(2-part keys starting with @).
|
🥺 |
|
View your CI Pipeline Execution ↗ for commit 4594bdb
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
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
leosvelperez
left a comment
There was a problem hiding this comment.
LGTM! 🚀
Thanks for the contribution!
Key optimisations: 1. Pre-computed PackageIndex - Built once during lockfile parsing: - byName: Map from package name → array of versions (O(1) lookup) - workspaceNames: Set of workspace package names (O(1) lookup) - workspacePaths: Set of workspace paths (O(1) lookup) - packagesWithWorkspaceVariants: Set of packages with workspace-specific variants (O(1) lookup) - patchedPackages: Set of patched package names (O(1) lookup) 2. findResolvedVersion: Changed from O(n) scan through all packages to O(1) map lookup + O(k) where k = number of versions for that package (typically 1-3) 3. isWorkspacePackage: Changed from O(n) scan to O(1) set lookup 4. hasWorkspaceSpecificVariant: Changed from O(n) scan to O(1) set lookup 5. isNestedPackageKey: Now uses pre-computed workspace paths/names sets instead of computing them each call On my 40 project typescript monorepo my time goes from about 30 seconds to 4.5s, a speed-up of 6-7x. --------- Co-authored-by: Leosvel Pérez Espinosa <[email protected]>
|
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. |
Key optimisations:
On my 40 project typescript monorepo my time goes from about 30 seconds to 4.5s, a speed-up of 6-7x.