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

Use yarn nodeLinker: node-modules to make tests faster #652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

geigerzaehler
Copy link
Contributor

This change almost halves the execution time of main.test.ts (from 57s to 35s on my machine using NOCK_ENV=replay). I expect similar results on CI.

The end-to-end tests run corepack in a new node process about 150 times. With the pnp linker, node is asked to require .pnp.cjs on every startup which significantly contributes to test time.

As an alternative, I tried removing --require=.pnp.cjs from NODE_OPTIONS in runCli. After all, we’re running the bundled version of corepack. But this did not work because tests/recordRequests.js is also required which in turn needs better-sqlite3.

This change almost halves the execution time of `main.test.ts` (from 57s
to 35s on my machine using NOCK_ENV=replay).

The end-to-end tests run corepack in a new node process about 150 times.
With the pnp linker, node is asked to require `.pnp.cjs` on every
startup which significantly contributes to test time.
@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Feb 12, 2025

@geigerzaehler
Copy link
Contributor Author

I expect similar results on CI.

Yeah, for the Node 22 test on Ubuntu total job time drops by 40s to 1min. And on Windows it drops by 3:40 to 8min.

@aduh95 aduh95 requested review from merceyz and arcanis February 12, 2025 11:57
Copy link
Contributor

@arcanis arcanis left a comment

Choose a reason for hiding this comment

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

I don't mind, it's true that we're in kind of a special case here since we're spawning a very large amount of subprocesses in our tests.

Comment on lines +9 to +10
- "main": "lib/advanced/index",
+ "main": "lib/advanced/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why those changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the original patch I get the following error:

Error: Directory import '.../corepack/node_modules/clipanion/lib/platform' is not supported resolving ES modules imported from ...corepack/node_modules/clipanion/lib/advanced/Cli.mjs

In fact, Cli.mjs uses import ... from './platform' but Node requires relative import specifiers to always point to files. I guess this worked before because yarn’s resolver is implemented differently and supports relative package imports.

@aduh95

This comment was marked as resolved.

@MikeMcC399
Copy link
Contributor

@aduh95

Will you merge this? It seems like a good improvement.

@arcanis
Copy link
Contributor

arcanis commented Mar 24, 2025

I would prefer to keep PnP, if only to have a Node.js project dogfooding the default yarn install strategy. The perf impact is unfortunate, but 30% doesn't feel too dramatic an increase that this is a must-do.

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.

4 participants