Skip to content

fix(core): improve package-json createNode performance#33960

Merged
FrozenPandaz merged 4 commits intomasterfrom
perf/explicit-project-dependencies
Dec 19, 2025
Merged

fix(core): improve package-json createNode performance#33960
FrozenPandaz merged 4 commits intomasterfrom
perf/explicit-project-dependencies

Conversation

@meeroslav
Copy link
Contributor

@meeroslav meeroslav commented Dec 19, 2025

On test repo, the package-json:createNodes:isInPackageManagerWorkspacesTime takes:

  • Before the PR: 2356ms
  • With PR: 23ms

This is achieved by avoiding unnecessary use of minimatch when a direct string comparison is sufficient.

It also makes creation and logging of entire graph come down from 23.6s down to 18.5s

Current Behavior

Expected Behavior

Related Issue(s)

Fixes #

@meeroslav meeroslav self-assigned this Dec 19, 2025
@meeroslav meeroslav requested review from a team as code owners December 19, 2025 15:40
@meeroslav meeroslav requested a review from AgentEnder December 19, 2025 15:40
@vercel
Copy link

vercel bot commented Dec 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nx-dev Ready Ready Preview Dec 19, 2025 6:04pm

@meeroslav meeroslav changed the title fix(core): improve buildExplicitTypeScriptDependencies performance fix(core): improve buildExplicitTypeScriptDependencies and createNode performance Dec 19, 2025
@nx-cloud
Copy link
Contributor

nx-cloud bot commented Dec 19, 2025

View your CI Pipeline Execution ↗ for commit d8986b2

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 1h 7s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 25s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 11s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-19 19:03:45 UTC

@netlify
Copy link

netlify bot commented Dec 19, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit d8986b2
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69459231f6f30000084c867b
😎 Deploy Preview https://deploy-preview-33960--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

nx-cloud[bot]

This comment was marked as outdated.

@meeroslav meeroslav force-pushed the perf/explicit-project-dependencies branch from e5bd702 to 898448f Compare December 19, 2025 16:29
@meeroslav meeroslav changed the title fix(core): improve buildExplicitTypeScriptDependencies and createNode performance fix(core): improve package-json createNode performance Dec 19, 2025
nx-cloud bot and others added 2 commits December 19, 2025 16:31
Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

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

Important

A new CI pipeline execution was requested that may update the conclusion below...

Nx Cloud is proposing a fix for your failed CI:

These changes fix the TypeScript compilation error by updating the call site in packages/nx/plugins/package-json.ts to match the refactored function signature. The fix calls buildPackageJsonPatterns() first to generate the patterns object with performance-optimized lookup tables, then passes that object to buildPackageJsonWorkspacesMatcher(), maintaining the PR's performance improvements while resolving the TS2554 error across all test suites.

We verified this fix by re-running docker:test, express:test, nest:test.

diff --git a/packages/nx/plugins/package-json.ts b/packages/nx/plugins/package-json.ts
index 53a032fe0c..335af6b85e 100644
--- a/packages/nx/plugins/package-json.ts
+++ b/packages/nx/plugins/package-json.ts
@@ -1,6 +1,7 @@
 import { createNodesFromFiles, NxPluginV2 } from '../src/project-graph/plugins';
 import { workspaceRoot } from '../src/utils/workspace-root';
 import {
+  buildPackageJsonPatterns,
   buildPackageJsonWorkspacesMatcher,
   createNodeFromPackageJson,
 } from '../src/plugins/package-json';
@@ -34,10 +35,11 @@ const plugin: NxPluginV2 = {
     (configFiles, options, context) => {
       const cache = readPackageJsonConfigurationCache();
 
-      const isInPackageJsonWorkspaces = buildPackageJsonWorkspacesMatcher(
-        context.workspaceRoot,
-        (f) => readJsonFile(join(context.workspaceRoot, f))
+      const patterns = buildPackageJsonPatterns(context.workspaceRoot, (f) =>
+        readJsonFile(join(context.workspaceRoot, f))
       );
+      const isInPackageJsonWorkspaces =
+        buildPackageJsonWorkspacesMatcher(patterns);
 
       const result = createNodesFromFiles(
         (packageJsonPath) =>

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally fJ2V-8skl

Apply fix locally with your editor ↗   View interactive diff ↗


🎓 Learn more about Self-Healing CI on nx.dev

@FrozenPandaz FrozenPandaz merged commit ab82bfe into master Dec 19, 2025
20 checks passed
@FrozenPandaz FrozenPandaz deleted the perf/explicit-project-dependencies branch December 19, 2025 22:38
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants