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

Run ESLint in parallel for multiple Nx projects #652

Open
9 tasks
matejchalk opened this issue Apr 25, 2024 · 4 comments
Open
9 tasks

Run ESLint in parallel for multiple Nx projects #652

matejchalk opened this issue Apr 25, 2024 · 4 comments
Assignees
Labels
Milestone

Comments

@matejchalk
Copy link
Collaborator

User story

For large Nx monorepos, it could help speed up Code PushUp runs if ESLint could run on different projects in parallel instead of sequentially. Adding an option to enable parallel execution, and even set the max number of processes, would give Code PushUp users more flexibility to optimize for performance. A lot like Nx's --parallel flag.

Acceptance criteria

  • new parallel?: boolean | number option is added to eslintPlugin initializer
  • default is to lint projects sequentially - so effective default is parallel: false
  • if an integer is specified (e.g. parallel: 4), then projects are chunked by this max value
    • within each chunk, processes are executed in parallel using Promise.all and executeProcess
    • chunks are executed sequentially
  • parallel: true enables parallel execution with maximum set to os.cpus().length
  • for future reusability, a generic function which orchestrates this sequential/parallel process execution is exported from @code-pushup/utils
  • test performance impact on some large Nx monorepos
  • document usage in @code-pushup/eslint-plugin

Implementation details

No response

@getlarge
Copy link
Collaborator

Have you considered using the worker_threads module from node to run in parallel? I would not be surprised if Nx would use a similar approach where the integer passed to parallel is the number of workers.

@getlarge
Copy link
Collaborator

Have you considered using the worker_threads module from node to run in parallel? I would not be surprised if Nx would use a similar approach where the integer passed to parallel is the number of workers.

My assumption was incorrect!

@vmasek vmasek modified the milestones: 3. Presentation, 4. Public Apr 25, 2024
@matejchalk
Copy link
Collaborator Author

I guess that could also work. I'm honestly not sure what the pros/cons would be of multi-threading instead of multi-processing. Since we're already using processes on the project (eslint is executed as a process, and we have a convenient executeProcess wrapper which promisifes spawn from child_process module), they should be more straightforward to implement. But could be worth investigating threads as an alternative.

@vmasek
Copy link
Collaborator

vmasek commented Mar 15, 2025

There is a benefit to use multi threading as it is generally faster to spin up, has less overhead (memory & CPU resources) but it's biggest benefit shared memory access is also a risk.

I agree that spawning process is already established as go to approach in the codebase and it has some benefits, namely we do not risk memory race conditions or need to be afraid that error would kill the whole execution of the CLI.

I plan to give this issue a try in following weeks with a POC

@vmasek vmasek self-assigned this Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants