You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Performance - Reduce build time and memory usage #4765
It will be hard to decouple Docusaurus totally from Webpack at this point.
But we should at least provide a way for users to use an alternative (non-Babel) JS loader that could be faster and good enough. Docusaurus core should be able to provide a few alternate loaders that would work by default using the theme classic, by just switching a config flag.
If successful and faster, we could make one of those alternate loader the default loader for new sites (when no custom babel config is found in the project).
Reacted by xiaody, David Blass, Felipe Torres (fforres), Theo Paris, Cody Ebberson, Max Schmitt, Santiago Fraire Willemoes, Josh Ghoulberg 👻, Pier-Luc Gendreau, Bryan Hoang and 31 more
changed the title [-]Decrease build time - use alternative webpack JS loaders[/-][+]Reduce build time - use alternative webpack JS loaders[/+]on May 11, 2021
We don't document it yet (apart here).
We may recommend it later for larger sites if it proves to be successful according to feedback from early adopters, so please let us know if that works for your use-case.
Important notes:
Docusaurus.io builds with esbuild and the above config
browser support seems good enough with es2017, and Docusaurus theme works in a lot of recent browsers
use a tool like Browserstack to test browser support (it's easy to get a free account for open-source projects)
eventually, use polyfill.io for even older browsers when some DOM APIs are unsupported?
Reacted by Nam Hoang Le, David Blass, Anton Kastritskii, Sibelius Seraphini, Kevin Hu, Cody Ebberson, Zena, miguelSWE, Daniel Salazar, SubJunk and 5 more
This gave a nice performance boost, although I think there are still more to be desired. Out of curiosity, what is actually going on that is taking so much time behind the scenes? In our case (a site with around 2,000 .md(x) files) most of the time spent seems to be before and after the "Compiling Client/Compiling Server" progress bars appear and complete.
As it stands, building the site takes around 20 minutes with esbuild, and was closer to 40 minutes before. Then out of curiosity, I just tested to add four versions to our site, and building it. Before using esbuild, the process took just shy of 13 hours(!). Using esbuild it was down to just shy of 8 hours. (Still way too long to be acceptable). So while it was a big improvement, it still seems to be very slow.
In the second case, it reported:
[success] [webpackbar] Client: Compiled successfully in 1.33h
[success] [webpackbar] Server: Compiled successfully in 1.36h
What was going on for the remaining 5 hours? Is this normal behavior, or did we configure something incredibly wrong? And why does it take much longer than four times the amount of time with four versions added?
@alphaleonis it's hard to say without further analysis, but the MDX compiler is transforming each md doc to a React component, that is later processed by babel (or esbuild).
The MDX compiler might be a bottleneck, this is why I'd like to provide an alternate MD parser for cases where MDX is not really needed.
Webpack might also be a bottleneck.
Using esbuild is not enough. Also when using esbuild as a webpack loader, we are not really leveraging the full speed benefits of esbuild. Unfortunately we can't replace replace Webpack by esbuild easily, it's part of our plugin lifecycle API and Webpack is more featured than esbuild (we use various things like file-loader, svgr loader...)
What was going on for the remaining 5 hours? Is this normal behavior, or did we configure something incredibly wrong?
We have enabled Webpack 5 has persistent caching, and rebuild times are much faster. You need to persist node_modules/.cache across build to leverage it.
And why does it take much longer than four times the amount of time with four versions added?
It's hard to tell without measuring on your system. Your system may have not enough memory for Webpack to do its job efficiently, leading to more garbage collection or whatever.
@slorber Thanks for the explanation. We did try the persistent caching, and it seems to help a lot with the time spent during the "Build server/client" phase (which I assume is Webpack). The machine in question had 16GB memory, and the same was specified as max_old_space_size.
Is there any way we can do some further analysis, such as enabling some verbose logging to get some more details perhaps? Or is this kind of the expected build time for sites of that size? (If so I guess we will have to find another solution for versioning, such as building/deploying each version separately.
Is there any way we can do some further analysis, such as enabling some verbose logging to get some more details perhaps?
This is a Webpack-based app, and the plugin system enables you to tweak the Webpack config to your needs (configureWebpack lifecycle) and add logs or whatever you want that can help troubleshoot the system. You can also modify your local docusaurus and add tracing code if you need.
I'm not an expert in Webpack performance debugging so I can't help you much on how to configure webpack and what to measure exactly, you'll have to figure out yourself for now.
Or is this kind of the expected build time for sites of that size?
It's hard to have meaningful benchmarks. Number of docs is one factor but also the size of docs obviously matter so one site is not strictly comparable to another. 40min build time for 2000 mdx docs with babel seems expected when comparing with other sites. Obviously it's too much and we should aim to reduce that build time, but it's probably not an easy thing to do.
(If so I guess we will have to find another solution for versioning, such as building/deploying each version separately.
For large sites, it's definitively the way to go, and is something I'd like to document/encourage more in the future.
It's only useful to keep multiple versions in master when you actively update them.
Once a version becomes unmaintained, you should rather move it to a branch and create a standalone immutable deployment for it, so that your build time does not increase as time passes and your version number increase.
We have made it possible to include "after items" in the version dropdown, so that you can include external links to older versions, and we use it on the Docusaurus site itself:
I also want to have a "docusaurus archive" command to support this workflow better, giving the ability to publish a standalone version of an existing site and then remove that version.
with Docusaurus 2.0.0-beta.0, doc site generation finished in 63min
with latest in-dev version, doc site generation finished in 30min.
Reduced 50% time. 👍
Saddly the process costs a very large memory.
My local testing environment has 32G memory, but in CICD environment memory limit is 20G. The process is killed cause of OOM, during emitting phase. From the monitor, the memory suddenly increased from 8G to 20G+.
It is unexpected that beta.2 is faster than beta.0, maybe you didn't clear your cache?
I'm using the esbuild-loader config from the docusaurus website example. So it should be esbuild making build faster.
What do you mean by the "emitting phase"? I didn't take much time to investigate all this so any info can be useful.
This may not be accurate. The process memory was 7G most times. About 20 minutes later memory jumped to 20.2G while the console showing Client "emitting". After client build finished, the memory dropped down to 7G. (The Server was still building)
changed the title [-]Performance - Reduce build time and memory usage - use alternative webpack JS loaders[/-][+]Performance - Reduce build time and memory usage[/+]on Oct 17, 2024
The "faster" option is opt-in. It's a breaking change only if you turn it on, although most sites should be able to adopt it relatively easily.
Activating this option should have a significant impact on build time and memory consumption.
You can try a Docusaurus canary right now and let me know how fast it is. It is relatively stable and ready to release, I'm just polishing the last details and writing docs before tagging v3.6.
@Airkro, it won't be stable until Docusaurus v4 because it's a breaking change anyway, Rspack is not 100% retrocompatible with webpack, and we can't guarantee a seamless upgrade for absolutely all of our sites. It doesn't mean it doesn't work well, and many large sites have already adopted it successfully.
I'm also still working on performance improvements, so it may even be a bit too soon for Docusaurus v4 to use Docusaurus Faster by default, considering I'm still working on improvements and we need community feedback/adoption. If we turn on Docusaurus Faster by default, we'll likely provide an opt out to restore former behavior.
You can always tweak our default webpack client/server dev/prod configurations, thanks to the plugin lifecycle methods
Last time I tried using lazyCompilation, it didn't work well at all; the site couldn't build, and the errors were unhelpful in troubleshooting the problem. If you were able to run your site with this option, please let me know how or provide a repro. I'm looking to adopt it for Docusaurus.
Only using lazyCompilation in development mode (docusaurus start) can delay many unnecessary builds. It only works with devServer, not for building, but it still helps when the site becomes bigger and slower.
You may see page loading fail or blank pages(can be fixed by page refresh), but it will usually work fine.
If the docusaurus framework uses more React.lazy + Suspense fallback, it will have more obvious improvements.
I came across this error #8329 in the Github CI/CD running docusaurus build.
What's actually scaling docusaurus's webpack phase memory usage? Is it the number of assets going through the webpack pipeline? If so increasing the heap memory will just fail once there's too many blog pages that feature some image or something. That's not really scalable.
What's the solution here, only use static URL paths and avoid the webpack pipeline? Or some way of making webpack discard un-used memory as much as possible?
@CMCDragonkai if you encounter a perf issue on a site it would be helpful to open a separate issue with all the details, otherwise it's really hard to do anything. If the site is https://polykey.com/docs then the first step would be to upgrade it to our latest release and turn on all the Docusaurus Faster options. I have no idea what you mean by "static URL paths".
I shifted all static assets out of the webpack pipeline by referencing via pathname. I benchmarked webpacks memory usage too and it appears to be dropped by 1GiB. But it was getting bigger and bigger the more assets (images mainly I was referencing in docusaurus). So I actually think the webpack pipeline is only good for UI assets, for non-UI assets like content assets it has to use the static paths. And do direct cachebusting.
Activity
[-]Decrease build time[/-][+]Decrease build time - use alternative webpack JS loaders[/+][-]Decrease build time - use alternative webpack JS loaders[/-][+]Reduce build time - use alternative webpack JS loaders[/+]slorber commentedon May 14, 2021
For anyone interested, we added the ability to customize the jsLoader here #4766
This gives the opportunity to replace babel by esbuild, and you can add this in your config:
We don't document it yet (apart here).
We may recommend it later for larger sites if it proves to be successful according to feedback from early adopters, so please let us know if that works for your use-case.
Important notes:
adventure-yunfei commentedon Jun 15, 2021
came from #4785 (comment).
Just wondering, is this issue aiming to reduce build time for entire site generator (including md/mdx parser, or Docs), or just jsx react pages?
slorber commentedon Jun 15, 2021
@adventure-yunfei md docs are compiled to React components with MDX, and the alternative js loader like esbuild also process the output of the MDX compiler, so this applies to documentation as well. Check the mdx playground to test the mdx compiler: https://mdxjs.com/playground/
If you have 10k docs you basically need to transpile 10k react components
adventure-yunfei commentedon Jun 15, 2021
@slorber perfect! we're also trying to use esbuild to boost build time (for application project). I'll have a try on this.
BTW I've created a similar large doc site here from our internal project.
Update:
Tested with a higher perf PC:
Reduced 50% time. 👍
alphaleonis commentedon Jun 23, 2021
This gave a nice performance boost, although I think there are still more to be desired. Out of curiosity, what is actually going on that is taking so much time behind the scenes? In our case (a site with around 2,000 .md(x) files) most of the time spent seems to be before and after the "Compiling Client/Compiling Server" progress bars appear and complete.
As it stands, building the site takes around 20 minutes with esbuild, and was closer to 40 minutes before. Then out of curiosity, I just tested to add four versions to our site, and building it. Before using esbuild, the process took just shy of 13 hours(!). Using esbuild it was down to just shy of 8 hours. (Still way too long to be acceptable). So while it was a big improvement, it still seems to be very slow.
In the second case, it reported:
What was going on for the remaining 5 hours? Is this normal behavior, or did we configure something incredibly wrong? And why does it take much longer than four times the amount of time with four versions added?
slorber commentedon Jun 23, 2021
@alphaleonis it's hard to say without further analysis, but the MDX compiler is transforming each md doc to a React component, that is later processed by babel (or esbuild).
The MDX compiler might be a bottleneck, this is why I'd like to provide an alternate MD parser for cases where MDX is not really needed.
Webpack might also be a bottleneck.
Using esbuild is not enough. Also when using esbuild as a webpack loader, we are not really leveraging the full speed benefits of esbuild. Unfortunately we can't replace replace Webpack by esbuild easily, it's part of our plugin lifecycle API and Webpack is more featured than esbuild (we use various things like file-loader, svgr loader...)
We have enabled Webpack 5 has persistent caching, and rebuild times are much faster. You need to persist
node_modules/.cacheacross build to leverage it.It's hard to tell without measuring on your system. Your system may have not enough memory for Webpack to do its job efficiently, leading to more garbage collection or whatever.
alphaleonis commentedon Jun 23, 2021
@slorber Thanks for the explanation. We did try the persistent caching, and it seems to help a lot with the time spent during the "Build server/client" phase (which I assume is Webpack). The machine in question had 16GB memory, and the same was specified as
max_old_space_size.Is there any way we can do some further analysis, such as enabling some verbose logging to get some more details perhaps? Or is this kind of the expected build time for sites of that size? (If so I guess we will have to find another solution for versioning, such as building/deploying each version separately.
johnnyreilly commentedon Jun 23, 2021
This is true - but there's still a speed benefit to take advantage of. It's also pretty plug and play to make use of. See my post here:
https://blog.logrocket.com/webpack-or-esbuild-why-not-both/
slorber commentedon Jun 24, 2021
This is a Webpack-based app, and the plugin system enables you to tweak the Webpack config to your needs (
configureWebpacklifecycle) and add logs or whatever you want that can help troubleshoot the system. You can also modify your local docusaurus and add tracing code if you need.I'm not an expert in Webpack performance debugging so I can't help you much on how to configure webpack and what to measure exactly, you'll have to figure out yourself for now.
It's hard to have meaningful benchmarks. Number of docs is one factor but also the size of docs obviously matter so one site is not strictly comparable to another. 40min build time for 2000 mdx docs with babel seems expected when comparing with other sites. Obviously it's too much and we should aim to reduce that build time, but it's probably not an easy thing to do.
For large sites, it's definitively the way to go, and is something I'd like to document/encourage more in the future.
It's only useful to keep multiple versions in master when you actively update them.
Once a version becomes unmaintained, you should rather move it to a branch and create a standalone immutable deployment for it, so that your build time does not increase as time passes and your version number increase.
We have made it possible to include "after items" in the version dropdown, so that you can include external links to older versions, and we use it on the Docusaurus site itself:
I also want to have a "docusaurus archive" command to support this workflow better, giving the ability to publish a standalone version of an existing site and then remove that version.
adventure-yunfei commentedon Jun 26, 2021
Saddly the process costs a very large memory.
My local testing environment has 32G memory, but in CICD environment memory limit is 20G. The process is killed cause of OOM, during emitting phase. From the monitor, the memory suddenly increased from 8G to 20G+.
slorber commentedon Jun 26, 2021
It is unexpected that beta.2 is faster than beta.0, maybe you didn't clear your cache?
What do you mean by the "emitting phase"? I didn't take much time to investigate all this so any info can be useful.
adventure-yunfei commentedon Jun 27, 2021
I'm using the esbuild-loader config from the docusaurus website example. So it should be esbuild making build faster.
This may not be accurate. The process memory was 7G most times. About 20 minutes later memory jumped to 20.2G while the console showing Client "emitting". After client build finished, the memory dropped down to 7G. (The Server was still building)
119 remaining items
Romej commentedon Jul 25, 2024
I would love to use docusaurus with rspack, we had many legacy CRA projects and we successfully migrated all of them to rspack without much efforts.
with rspack 1.0 around the corner, i am hoping this will be an option soon
clainchoupi commentedon Sep 4, 2024
OzakIOne commentedon Sep 4, 2024
clainchoupi commentedon Sep 5, 2024
slorber commentedon Sep 5, 2024
[-]Performance - Reduce build time and memory usage - use alternative webpack JS loaders[/-][+]Performance - Reduce build time and memory usage[/+]slorber commentedon Oct 22, 2024
FYI Docusaurus v3.6 is entirely focused on performance - see the Docusaurus Faster project
The "faster" option is opt-in. It's a breaking change only if you turn it on, although most sites should be able to adopt it relatively easily.
Activating this option should have a significant impact on build time and memory consumption.
You can try a Docusaurus canary right now and let me know how fast it is. It is relatively stable and ready to release, I'm just polishing the last details and writing docs before tagging v3.6.
slorber commentedon Nov 4, 2024
Docusaurus v3.6 is out with the Docusaurus Faster options 🥳 🎉
https://docusaurus.io/blog/releases/3.6
Airkro commentedon May 15, 2025
Docusaurus Fasteris still not stable.Please consider using
options.experiments.lazyCompilationof webpack. It makes everything faster when in dev mode.Only need more
<Suspense>to support it better.slorber commentedon May 15, 2025
@Airkro, it won't be stable until Docusaurus v4 because it's a breaking change anyway, Rspack is not 100% retrocompatible with webpack, and we can't guarantee a seamless upgrade for absolutely all of our sites. It doesn't mean it doesn't work well, and many large sites have already adopted it successfully.
I'm also still working on performance improvements, so it may even be a bit too soon for Docusaurus v4 to use Docusaurus Faster by default, considering I'm still working on improvements and we need community feedback/adoption. If we turn on Docusaurus Faster by default, we'll likely provide an opt out to restore former behavior.
You can always tweak our default webpack client/server dev/prod configurations, thanks to the plugin lifecycle methods
Last time I tried using
lazyCompilation, it didn't work well at all; the site couldn't build, and the errors were unhelpful in troubleshooting the problem. If you were able to run your site with this option, please let me know how or provide a repro. I'm looking to adopt it for Docusaurus.Airkro commentedon May 15, 2025
Only using
lazyCompilationin development mode (docusaurus start) can delay many unnecessary builds. It only works withdevServer, not for building, but it still helps when the site becomes bigger and slower.You may see page loading fail or blank pages(can be fixed by page refresh), but it will usually work fine.
If the docusaurus framework uses more
React.lazy + Suspense fallback, it will have more obvious improvements.CMCDragonkai commentedon Mar 6, 2026
I came across this error #8329 in the Github CI/CD running
docusaurus build.What's actually scaling docusaurus's webpack phase memory usage? Is it the number of assets going through the webpack pipeline? If so increasing the heap memory will just fail once there's too many blog pages that feature some image or something. That's not really scalable.
What's the solution here, only use static URL paths and avoid the webpack pipeline? Or some way of making webpack discard un-used memory as much as possible?
slorber commentedon Mar 6, 2026
@CMCDragonkai if you encounter a perf issue on a site it would be helpful to open a separate issue with all the details, otherwise it's really hard to do anything. If the site is https://polykey.com/docs then the first step would be to upgrade it to our latest release and turn on all the Docusaurus Faster options. I have no idea what you mean by "static URL paths".
CMCDragonkai commentedon Mar 7, 2026
I shifted all static assets out of the webpack pipeline by referencing via pathname. I benchmarked webpacks memory usage too and it appears to be dropped by 1GiB. But it was getting bigger and bigger the more assets (images mainly I was referencing in docusaurus). So I actually think the webpack pipeline is only good for UI assets, for non-UI assets like content assets it has to use the static paths. And do direct cachebusting.
Yes I'm in docusaurus 3.9.