-
-
Notifications
You must be signed in to change notification settings - Fork 67
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: Add poolRespawn
option to speed up incremental builds
#52
Conversation
Codecov Report
@@ Coverage Diff @@
## master #52 +/- ##
=========================================
+ Coverage 16.94% 19.9% +2.96%
=========================================
Files 7 7
Lines 425 432 +7
Branches 71 74 +3
=========================================
+ Hits 72 86 +14
+ Misses 310 305 -5
+ Partials 43 41 -2
Continue to review full report at Codecov.
|
/cc @mistic for me looks good, what do you think? |
Cool if we change it to be the default it would also solve #26. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jantimon just left a group of suggestions to make the implementation more clear and basically terminating the Worker pool after disposing when poolRespawn is false
@mistic you are right we could reuse the I updated my pull request accordingly. |
@jantimon I was writing down this when u wrote down your comment haha! Awesome, it's much better right now! What do you think of, to finish, just do this instead of what is actually being done? // Replace pitch() function on index.js
function pitch() {
const options = loaderUtils.getOptions(this) || {};
const workerPool = getPool(options);
workerPool.run({
loaders: this.loaders.slice(this.loaderIndex + 1).map((l) => {
return {
loader: l.path,
options: l.options,
ident: l.ident,
};
}),
resource: this.resourcePath + (this.resourceQuery || ''),
sourceMap: this.sourceMap,
emitError: this.emitError,
emitWarning: this.emitWarning,
resolve: this.resolve,
target: this.target,
minimize: this.minimize,
resourceQuery: this.resourceQuery,
optionsContext: this.rootContext || this.options.context,
}, this);
}
// Replace run() function on WorkerPool.js into WorkerPool class
run(data, pitchContext) {
// Return right away if we have terminated and workerPool
// is not configured to respawn
if (this.terminated && !this.options.poolRespawn) {
return;
}
// Indicate to loader runner that it should wait
// for an async operation calling the async from the
// given pitchContext
const pitchContextAsyncCallback = pitchContext.async();
// Build the callback for the workerPool queue call
// when this job complete
const runCallback = (err, r) => {
if (r) {
r.fileDependencies.forEach(d => this.addDependency(d));
r.contextDependencies.forEach(d => this.addContextDependency(d));
}
if (err) {
pitchContextAsyncCallback(err);
return;
}
pitchContextAsyncCallback(null, ...r.result);
return;
};
// Taking care of the time out,
// incrementing the active jobs
// and add the job to the workerPool queue
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = null;
}
this.activeJobs += 1;
this.poolQueue.push(data, runCallback);
} |
Is that code change related to this merge request? If I understand it correct I am not sure why you would like to move this part away from the pitch loader and move it over to the responsibility of the WorkerPool. |
@jantimon the changes I proposed in the comment above they are just to encapsulate the code and run the logic inside the the if (this.terminated && !this.options.poolRespawn) {
return;
} |
@mistic okay I understand what you mean. Now it is only:
Please take a look if that might already be enough.
Imho that way we would not mix up the responsibilities. |
I'm not sure this fixes #37. |
@a-aslan feel free to investigate and send a PR with fix |
This is not related to #37. |
@jantimon I like your second idea! If it was on me, I would rather prefer to run those checks inside the run function itself, but I'm fine with both! Be free to commit the updates! |
@mistic done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Something wrong with CI, need fix |
Need rebase too 👍 |
fdfea8f
to
4c43159
Compare
Added tests and rebased to master :) |
@jantimon Great! |
The thread-loader doubled the build duration for incremental builds because of the WorkerPool which is disposed after 500ms by default.
This pr tries adds
poolRespawn:false
to solve this problem similar topoolTimeout: Infinity
. If set tofalse
it will not respawn a worker pool once it was disposed.So unlike
poolTimeout: Infinity
this feature allows to use the thread-loader only for the initial build.The idea behind that is that the initial startup has to transpile all files but incremental builds usually transpile only a single file.
As this would have no negative impact for a production webpack-cli build we might even set
poolRespawn:false
as default.Please let me know if that would be okay for you so I can adjust this pr.