Skip to content
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(perf): only initialize workpaces when we are inside a workspace #7360

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

H4ad
Copy link
Contributor

@H4ad H4ad commented Apr 10, 2024

If we didn't load glob, we can save up to 6ms by lazy loading this module.

@wraithgar
Copy link
Member

Only 14 commands call setWorkspaces

$ grep -rc setWorkspaces lib/commands/|grep -v "0\$"
lib/commands//exec.js:1
lib/commands//owner.js:1
lib/commands//run-script.js:2
lib/commands//pack.js:1
lib/commands//query.js:1
lib/commands//version.js:3
lib/commands//init.js:1
lib/commands//publish.js:1
lib/commands//unpublish.js:1
lib/commands//dist-tag.js:1
lib/commands//view.js:1
lib/commands//sbom.js:1
lib/commands//pkg.js:1
lib/commands//diff.js:1

@wraithgar wraithgar merged commit 64bcf4c into npm:latest Apr 10, 2024
19 of 20 checks passed
wraithgar pushed a commit to npm/package-json that referenced this pull request Apr 10, 2024
Since npm run didn't call those steps, we can save some `ms` by lazy
loading this dependency.

Before:


![image](https://github.com/npm/package-json/assets/12551007/b4654691-85c8-4431-ba60-f7188363a125)

After:


![image](https://github.com/npm/package-json/assets/12551007/f3b02669-2070-4171-aeda-90954c55f54d)

The entire load time didn't change, still `13ms` before & after, but if
we call `npm run` inside a project that didn't have workspaces, we will
save some `ms`, like this one:


![image](https://github.com/npm/package-json/assets/12551007/0fe98367-4967-40f2-8d71-2a1b8c4eda55)

But this will also require the PR npm/cli#7360
to be merged.
@github-actions github-actions bot mentioned this pull request Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants