-
-
Notifications
You must be signed in to change notification settings - Fork 69
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(threadpool): expose node worker-threads pool adapter #81
base: master
Are you sure you want to change the base?
Conversation
As |
using jest-worker or other existing pool impl won't allow interop point to marshall webpack's loadercontext fn to worker thread. Due to those reason this PR may not work on some loaders, reason impl https://www.npmjs.com/package/webpack-loader-worker uses custom threadpool instead: (https://github.com/kwonoj/webpack-loader-worker/blob/master/src/threadPool.ts) Still it doesn't require ipc serialization (most POJO can be cloned, only fn requires proxy) serialization logics are much simpler. |
One challenge in the current thread-loader implementation was to efficiently pass Buffers from and to workers. Currently this is done by avoiding all serialization/ipc techniques and passing raw buffers via input/output streams. I really appreciate a worker_threads implementation, especially as it could leverage a more efficient way of passing Buffers from and to workers. This means using a library for abstracting worker_threads, may or may not have drawbacks here. I actually didn't look into your PR in detail, which leads me to the question: Is |
You may refer https://github.com/kwonoj/webpack-loader-worker for more completed proposal. To answer your q
|
As fyi, general perf around structured clone is well explained here: https://dassur.ma/things/is-postmessage-slow/. I think considering other alternative would makes sense if structured clone is proven to slower than current out-of-proc communication. |
PR now updated to port working poc code from module. (Lot of things are failing, wanted to share poc to kick off discussion to move on actual work) |
Forgot to mention updated changes from https://github.com/kwonoj/webpack-loader-worker have the possibility to support buffer transfer via |
@sokra and this change shows some example |
How is the performance? Would this help lift some of the limitations? |
Hello, any update about this feature ? |
Description
This PR attempts to discuss way to utilize
worker_threads
in node.js as runner for thread-loader execution.thread-loader
option exposesuseThreadPool
, which will create newThreadPool
instance instead of existing worker pool. New ThreadPool is naive adapter interface to conform existing workerPool behavior, while accepts limited options (workerType, maxWorker) compare to original workerpool. Once new pool is initializedloader-runner
will be executed under each worker thread.Due to the different nature of worker thread to process based thread, replacing existing implementation to worker thread will create major breaking changes from options to some behavior (i.e
warmup
is no-op). Once it is verified to have near-feature parity / also majority of userbase have node.js supports thread, can flip switch to trigger breaking changes.What to do
[ ] is this PR makes sense?
[ ]
Is it ok to useneeds custom threadpool to support non-transferrable object (mostly functions) communication between main - worker thread.workerpool
to manage workers? or should write own pool instead? or other alternative likejest-worker
? (https://github.com/facebook/jest/tree/master/packages/jest-worker)[ ] unit test
[ ] basic e2e test allows manual auditing build results
Things to note