Replies: 3 comments 4 replies
-
|
what's the behavior when user pass loader options that doesn't follow the specification? |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
it seems thread-loader is faster than |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
Does this feature support the sass-loader? I tested it and encountered a DataCloneError. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
PR: #9807
Motivation
Try to use
worker_threadsto run JavaScript loaders. This adds parallelism to the current JS loader.User guide
To enable parallelism, set either
Rule.use.parallel = trueandexperiments.parallelLoader = true:module.exports = { module: { rules: [ { test: /\.less$/, use: [ { loader: "less-loader", + parallel: true, options: { ... } } ] type: "css" } ] }, experiments: { css: true, + parallelLoader: true } }Detailed design
Worker threads
Unlike
thread-loader, rspack uses worker threads to drive loader tasks, usingtinypoolunder the hood. That said, loader options need to be serializable in order to be sent to the worker thread and not all methods are available inLoaderContext. Currently,importModuleand most of the methods of_compilation,_compiler,_moduleare missing.Loader runner
thread-loaderdispatches remaining loaders by default. If I writeuse: ["thread-loader", "css-loader", "less-loader"],css-loaderandless-loaderwould end up in the worker thread. This is not the same in rspack. You may consider the worker as a loader runner but in worker. If rspack encounters a loader that is setparallel: true, loader runner on the main thread would send the execution state to worker and yield if the next loader is notparallelor it's a rust builtin loader. This chains loaders withparallelenabled automatically, achieving the best performance.Handling synchronous calls
Worker threads are spawned on demand and, by default, is using the max thread available on the OS. In each worker, a channel is created to pass requests to the main thread for on-demand requesting, such as
LoaderContext["getResolve"]. That is to say, each request to the main thread is running asynchronously. This also requires most of the method ofLoaderContextto beasync. To make it compatible with synchronous loader context calls to the main thread, rspack uses an internal wrapper to wrap anasyncmethod into sync, by exposingwait()to each request. For example,addDependencydoes not resolve until the main thread yield, butgetDependencieswill wait until all previous adding operation to finish and get the latest dependencies in a synchronous call. This was achieved by putting the thread to sleep and waking it up when it's necessary.Caveats
importModule,_compilation,_compilerand_modulemethods.Benchmark
Building 100 copies of
antd.lesswithcss-loader,rspack-plugin-extract-cssandless-loader:Building 100 copies of
antd.lesswithexperiments.cssandless-loader:Benchmark was running on Apple M2 Max, 64G.
antd.lessis referenced from this.Beta Was this translation helpful? Give feedback.
All reactions