Repository navigation
Description
Describe the bug
On our current platform, we generate documentation using this generator. However, both with previous versions, as well as with the canary version using @docusaurus/faster, the memory consumption for building the documentation with generated OpenAPI documentation is significant.
When building documentation without the generated files, the total memory consumption is around 500m. When I include the generated files, at first, the memory consumption stays the same. However, it seems that when the css-loader step kicks in, that memory consumption skyrockets to 2.5g, increasing all the way to 3.5g until the end of the build. This is quite significant for 244 files.
When removing the actual contents of the generated files (that is, only including the front matter), the memory consumption peaks around 1g, which is more along the lines of what I expect.
Expected behavior
The documentation to build without a big increase in memory consumption.
Current behavior
During build (for as it seems, when reaching the css-loader step) the memory usage jumps to 2.5g and slowly rises to 3.5g until the build finishes.
Possible solution
For now, I do not know. I am willing to look into this issue to see if there are any ways to reduce required memory.
Steps to reproduce
- Take a relatively large openapi specification file.
- Follow the README to generate documentation for these specs. In my instance, I generated 244 files.
- Build the documentation in, for example, a Docker container to monitor the memory usage.
Screenshots
After sudden jump in memory usage:

Context
When building documentation in Docker containers, I want to restrict memory usage as the memory on the server is shared by various other containers. In case the build takes up too much memory, this will hinder other services/builds.
Your Environment
- Version used: canary
- Environment name and version: node 18
- Operating System and version (desktop or mobile): node:18-alpine (Docker)


Activity
sserrata commentedon Nov 19, 2024
Hi @Gijsdeman, thanks for highlighting this issue...I was curious if you've performed a similar experiment using docs not generated from the OpenAPI plugin, or if you believe the issue to be specific/isolated to the plugin/theme?
What I'm trying to determine is:
--no-minifyoption?Docs generated from OpenAPI specs can vary greatly in overall size, especially when you factor in deeply nested or expansive schemas, so that's another detail to consider/factor.
Gijsdeman commentedon Nov 19, 2024
Hi @sserrata, thanks for coming back to me.
I tested this with the biggest documentation that I know of myself; the Docusaurus documentation itself. This documentation fits the needs that you mention, but "only" peaks around
3g. While this is still a lot, this is something I expect from a documentation of that size.The instance I am building is significantly smaller. Yet, my memory usage is higher then when building the Docusaurus documentation. This makes me believe there is something present in the OpenAPI plugin that consumes a significant amount of memory.
It could indeed be that the complexity of the pages generated by the OpenAPI simply require all the memory to be compiled and bundled. Either way, I wanted to make this issue to check where the memory consumption might exactly originate from / if there are any possibilities to reduce the memory needs. Definitely since using the canary version in combination with
@docusaurus/fasterhas caused my memory to even increase slightly more (causing more container builds to fail), while my expectation what that this would reduce the memory need significantly.To sum up and answer your other questions:
--no-minifyoption (or similar approaches using rspack).sserrata commentedon Nov 19, 2024
Are we certain the "number of docs" is the correct way to look at this from a scaling issue? I would think that overall content size across all docs would matter more, especially as everything gets bundled together. I can totally see a situation where a few hundred generated API docs contains cumulatively more content than thousands of "non-API" docs. That said, 3GB is pretty close to the 3.5GB peak you referenced with respect to your build.
I don't doubt this is true but, again, I would focus more on overall accumulated content vs API/non-API docs.
I would reach out to the Docusaurus maintainers to inquire about the expected memory utilization and possible ways to optimize, you may even be able to comment on an existing issue. At the end of the day, our plugin/theme emits markdown and JSX/JS which, when taken at face value, isn't really "special" content when it comes to Docusaurus.
FWIW, today, it takes roughly an hour to build our site https://pan.dev, which publishes docs for over 30 APIs. Over the years, I've had to upgrade to larger and larger GitHub runners to accommodate the growth (currently using large runners with 32xCPU and 128GB RAM).
Gijsdeman commentedon Nov 20, 2024
This also seems reasonable and might be the case. I am not sure how to check this, but maybe it is indeed worth to start a discussion at Docusaurus instead to see what other people are experiencing in build times and performance results.
Thank you for this insight, I do not have much material to compare against. Like I said, I will likely start a conversation over at Docusaurus somewhere soon to see what other developers are experiencing, to see what might actually cause a build to slow down / consume a lot of memory.
In the end, thank you for sharing your experience. If I do open a discussion at Docusaurus, I will be sure to mention this issue here.
omonk commentedon Dec 6, 2024
To add to this discussion, we started seeing OOM errors for our build recently after adding a new version to our API docs. Our spec has 447 pages and going from 3 to 4 versions broke it, so 1,341 to 1,788. We have several other doc sections in our config, of which there are around 360 md[x] pages to build into HTML + JS.
In total we're now at at 2,148 pages.
We attempted to use the new faster build with
experimental_faster: trueconfiguration but this OOM'd very quickly, after some tweaking we've found we need to turn everything off apart from therspackBundleroptionMy experience with running node processes in the chrome debugger is very limited but I decided to give it a go yesterday. The following image is a visualisation of the memory heap once the main docusaurus client and server bundles are built 100%. It's not clear what is happening at this stage but if we comment out the openapi plugin, this does not happen.
Currently this works for us but I do suspect there is something in this plugin which is causing a memory leak.
sserrata commentedon Dec 6, 2024
Hi @omonk, can you provide more details on the OOM error you're seeing, i.e. the actual error? Also, what do you mean by "very quickly"? Typically, when I get a node heap OOM error it's cumulative, meaning I don't see it until toward the latter end of the build. Something else to pay special attention to is where the error occurs: are you seeing it while the plugin is generating the API docs or while the Docusaurus build is occurring?
Finally, what env are you observing the OOM error(s) in and what are the CPU/MEM specs? Take our site https://pan.dev for example, which contains over 17K docs across 30+ APIs, some with multiple versions. A production build using a large GitHub runner (32 cores and 128GB RAM) takes ~35-40 minutes using
docusaurus-fasterwith all options enabled. Performance is about the same for Docusaurus v2.4.3 usingswc-loader.sserrata commentedon Dec 6, 2024
Much different scenario when I attempt a build on my M1 Mac (16GB RAM) 😅
omonk commentedon Dec 9, 2024
Whilst the build is occurring, generating the files is fine.
We're deploying on vercel, 23 GB Disk space, 8192 MB Memory. I gotta say, 32 cores and 128GB RAM is a huge image.
Given we're only seeing this issue when we have the plugin enabled, I wonder whether duplicating the non API spec directories and including them in the build will produce the same OOM errors to see whether OOM is caused by just scaling so an issue with docusaurus rather than this plugin.
One thing I've noticed is that when the plugin is enabled and running the build command, after the client and server bars reach 100% the process doesn't log anything for a while. Do you know what work it happening at this stage? Looking at the theme and plugin packages, theres no usage of post build commands so perhaps there's something in some theme files which are causing a memory leak during SSR? Just spitballing!
After this long pause we see logs from the lunr search plugin generating the files required for the search.
Gijsdeman commentedon Dec 10, 2024
I did not specifically mention this in the thread, but also the point of memory increase from 2.5g to 3.5g that I referred to in the original issue. The rest of the build stays comparable to building documentation without the API docs, but at this stage the memory usages spikes.
sserrata commentedon Dec 10, 2024
Hi @Gijsdeman and @omonk, if you haven't already, I would recommend opening an issue on the Docusaurus repo, referencing this issue, so the maintainers can chime in.
omonk commentedon Jun 23, 2025
@Gijsdeman + @sserrata
Worth having a peek at this post in Docusaurus repo - meta/docusaurus#11199