Nodejs worker threads for build

bjunc
114
bjunc
commented 2 months ago

What problem does this feature solve?

The build time for a moderately sized application can get painfully slow. Changes to nuxt.config.js are especially bad. Even simple module swaps with a minor markup tweak can take a few seconds to refresh, often bringing down Vue dev tools after an hour or so of work.

I know there has been talk about using swc, but is there a potential stop-gap solution for faster builds? Could the client and server builds be moved to separate Node worker threads (currently experimental in v12)? Or is it maybe simpler to just use clustering to take advantage of multiple cores? Hopefully this isn't already in place, as that would mean we've already used up a lot of performance boost potential…

As JS applications are getting increasingly more complex, I think it's going to be an area of considerable pain for applications beyond toy size.

idea
0
pimlie
1.1k
pimlie
commented 2 months ago

We have some plans which should improve performance but those are on a larger scale and will probably only land in Nuxt v3. In the mean time any pr which improves performance (without breaking functionality) would be very welcome!

Even simple module swaps

That might be a bigger understatement that you would think at first. A module swap is never simple as a module could interact with every stage of the Nuxt build process. As nuxt doesnt know on before hand what changes a module causes, any touches to nuxt.config just triggers a full re-build of your Nuxt application. Unfortunately there is no easy way to optimize that (i.e. module swaps) at all.

There are also some experimental configuration options you could use, see eg cache, hardSource and parallel but setting those might break your project build.

0
bjunc
114
bjunc
commented a month ago

The parallel option seems similar to what I was referring to by using Node workers. Is there more information out there on how this configuration option specifically impacts Nuxt? For instance, if the thread-loader is at the loader level, which loaders are being farmed out to the worker pool?

I don't need a pharmaceutical disclaimer telling me how this feature may cause blindness and/or death, but a little transparency into what the pros/cons are would be very helpful.

0
Informations
Feature RequestOpen
#c9649 - Created 2 months ago