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

Speed up unit test suite performance #6753

Open
mourner opened this issue May 29, 2018 · 3 comments
Open

Speed up unit test suite performance #6753

mourner opened this issue May 29, 2018 · 3 comments

Comments

@mourner
Copy link
Member

mourner commented May 29, 2018

While trying to figure out why yarn run test-unit on the CI takes 6 minutes (which seems unreasonable), I discovered that there's a lot of overhead because we're running a new node process for every unit file. The ESM overhead for every file is typically 2–5 seconds (even if the tests inside run in 20ms), and there are 96 of them — each basically doing a custom build of Mapbox GL (depending on what's imported), that's executed by the VM after being built. The code is highly coupled, so for many files, those builds end up being pretty big.

Generally a 6-minute run isn't a problem because we can call individual test files when developing locally, and it's in parallel to 7-minute render tests, but reducing this time back to 2 minutes will free up Circle jobs, benefitting everyone.

I'm not sure what approach to take here though:

  • Tried iterating over all files and requiring them in the same context, but apparently some tests (and imports like jsdom) cause problems for other (unrelated) tests.
  • We could manually merge batches of test files together, but that will be quite a cumbersome undertaking and we'll have to find a compromise between maintainability and test suite performance.
  • I wonder if using --experimental-modules instead of esm would solve this — it could. Although switching away from esm will also be cumbersome (involving renaming all files to .mjs, and potentially changing the way we use CommonJS modules because of stricter interop).

Ideas? Should we bother?

cc @jfirebaugh

@anandthakker
Copy link
Contributor

involving renaming all files to .mjs

@mourner FWIW, I think there's a way we could add a custom Node loader hook to treat .js files as modules.

@asheemmamoowala
Copy link
Contributor

This has been reduced back down to <4m with the removal of ESM and switch to experimental module loaders. Closing this for now.

@mourner
Copy link
Member Author

mourner commented Mar 9, 2021

Worth noting that there's still a huge room for improvement — since we still run a separate node process for each unit test file, it runs all the loading and transforming repeatedly over and over again. If we could fix all unit tests to run in a single process, I believe the unit test time could be reduced to 1-2 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants