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

feat(terser): Update WorkerPool to reuse Workers #1409

Merged
merged 6 commits into from
Jan 23, 2023

Conversation

dasa
Copy link
Contributor

@dasa dasa commented Jan 19, 2023

Rollup Plugin Name: terser

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers: #1341 (review)

Description

The existing WorkerPool creates a new Worker instance for every chunk. This PR reuses them instead. There is still a max number of workers, and the pool size still increases based on demand up to this max.

In my testing, on a 10 CPU machine, this reduced the build time from about 4.5 minutes to 2.5 minutes. This is for a large project with about 8,000 chunks.

I refactored the WorkerPool based on this Node doc example. I changed it to not create all the workers immediately though since this isn't needed in simple cases.

The changes to module.ts are based on the logic in https://github.com/TrySound/rollup-plugin-terser/blob/master/rollup-plugin-terser.js This is needed since the Workers now need to be explicitly terminated.

Similar to PR #1394, this PR also improves the error messages.

@dasa
Copy link
Contributor Author

dasa commented Jan 20, 2023

@tada5hi can you review this please?

Copy link
Collaborator

@shellscape shellscape left a comment

Choose a reason for hiding this comment

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

tests included was checked, and while technically there are tests, they were only modified to check for a new error value. I'd like to see some more robust testing in place to prevent regression: something like providing some basic reporting from the plugin that we could analyze - namely the number of workers used, so that worker re-use could be verified. Note that I'm not speaking about log output specifically, but if that's the only option then that would work.

@dasa
Copy link
Contributor Author

dasa commented Jan 20, 2023

something like providing some basic reporting from the plugin that we could analyze

Is there another plugin that has something like this so I can see how the mechanics of that could work? e.g., is it another export from the index module? Currently the worker pool instance is in the scope of the default function exported from the module module.

@shellscape
Copy link
Collaborator

there isn't to my knowledge, which is part of the reason I left it open-ended. I wouldn't even care if it was really dirty, just seeking to protect your changes against regression in the future. Give it a poke, and if at the end you don't have anything that's usable for determining that in a test, we'll make a note and move on.

@tada5hi
Copy link
Member

tada5hi commented Jan 21, 2023

@tada5hi can you review this please?

@dasa left you some notes. Beside that, the pull request is looking good.

@dasa
Copy link
Contributor Author

dasa commented Jan 21, 2023

@shellscape I've updated the tests.

@tada5hi sorry, I'm not seeing the notes.

packages/terser/src/module.ts Outdated Show resolved Hide resolved
packages/terser/src/module.ts Show resolved Hide resolved
packages/terser/src/worker-pool.ts Outdated Show resolved Hide resolved
packages/terser/src/worker-pool.ts Outdated Show resolved Hide resolved
packages/terser/src/worker-pool.ts Outdated Show resolved Hide resolved
packages/terser/src/worker-pool.ts Outdated Show resolved Hide resolved
packages/terser/src/worker.ts Outdated Show resolved Hide resolved
@tada5hi
Copy link
Member

tada5hi commented Jan 21, 2023

@shellscape I've updated the tests.

@tada5hi sorry, I'm not seeing the notes.

sorry i forgot to submit the review 🙈

@dasa dasa requested a review from tada5hi January 22, 2023 17:31
@dasa
Copy link
Contributor Author

dasa commented Jan 23, 2023

@tada5hi I believe I've addressed all your feedback. Please let me know if there's anything else.

@tada5hi tada5hi merged commit 74dbb42 into rollup:master Jan 23, 2023
@shellscape
Copy link
Collaborator

@tada5hi please try to wait for two approvals, thats the standard we tend to follow. if after a week or so no one has stepped up to review, we'll ping people direct and if at that point it's crickets, we'll merge. we're definitely not in a rush to merge in this project.

@tada5hi
Copy link
Member

tada5hi commented Jan 23, 2023

@tada5hi please try to wait for two approvals, thats the standard we tend to follow. if after a week or so no one has stepped up to review, we'll ping people direct and if at that point it's crickets, we'll merge. we're definitely not in a rush to merge in this project.

@shellscape Oh dam I'm sorry about that. I assumed from past experience that one approval would be enough. I will definitely keep it in mind in the future and follow the convention. Would like to apologize again for the circumstances.

@shellscape
Copy link
Collaborator

No worries, no need to apologize. We should probably write that down somewhere.

@dasa dasa deleted the reuse-workers branch January 23, 2023 21:28
@tada5hi
Copy link
Member

tada5hi commented Jan 23, 2023

@shellscape Then I am reassured ☺️

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.

None yet

3 participants