Skip to content

Memory consumption / scalability issues #1025

Closed

Description

@Gijsdeman

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

  1. Take a relatively large openapi specification file.
  2. Follow the README to generate documentation for these specs. In my instance, I generated 244 files.
  3. Build the documentation in, for example, a Docker container to monitor the memory usage.

Screenshots

Start of the build:
specs-start

After sudden jump in memory usage:
specs-middle

At the end of the build:
specs-end

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

  1. added
    bug
    on Nov 19, 2024
  2. sserrata commented on Nov 19, 2024

    @sserrata
    Member

    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:

    • Could the scaling/build-perf issues be inherent to Docusaurus itself?
    • Do the build/memory issues occur even with non-API docs? Does it depend on the content mix, i.e. MDX/JSX, markdown, styles, etc.
    • Does memory consumption scale linearly as more docs are added? I would expect that to be the case today.
    • Does the behavior change or improve with the --no-minify option?

    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.

  3. Gijsdeman commented on Nov 19, 2024

    @Gijsdeman
    ContributorAuthor

    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/faster has 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:

    • Yes, it could very well be possible the the perf issues are inherent to Docusaurus itself and the complexity of the OpenAPI plugin. I am not sure how we could rule this possibility in/out.
    • The specific issues I am encountering -- sudden peaks in memory usage when building OpenAPI plugin generated docs -- is not something I am encountering with non-API docs.
    • The memory consumption scales linearly as more docs are added. Building the documentation with only a small amount of generated files is fast, and grows slower / more memory intensive as more files are added.
    • The behaviour does not change or improve when using the --no-minify option (or similar approaches using rspack).
  4. sserrata commented on Nov 19, 2024

    @sserrata
    Member

    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.

    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.

    The specific issues I am encountering -- sudden peaks in memory usage when building OpenAPI plugin generated docs -- is not something I am encountering with non-API docs.

    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).

  5. Gijsdeman commented on Nov 20, 2024

    @Gijsdeman
    ContributorAuthor

    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.

    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.

    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).

    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.

  6. omonk commented on Dec 6, 2024

    @omonk
    Contributor

    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: true configuration but this OOM'd very quickly, after some tweaking we've found we need to turn everything off apart from the rspackBundler option

    experimental_faster: {
      swcJsLoader: false,
      swcJsMinimizer: false,
      swcHtmlMinimizer: false,
      lightningCssMinimizer: false,
      rspackBundler: true,
      mdxCrossCompilerCache: false,
    },
    

    My 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.

    image

    Currently this works for us but I do suspect there is something in this plugin which is causing a memory leak.

  7. sserrata commented on Dec 6, 2024

    @sserrata
    Member

    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-faster with all options enabled. Performance is about the same for Docusaurus v2.4.3 using swc-loader.

  8. sserrata commented on Dec 6, 2024

    @sserrata
    Member

    Much different scenario when I attempt a build on my M1 Mac (16GB RAM) 😅

    [PERF] Get locales to build - 114.82 ms - (56mb -> 61mb)
    [INFO] [en] Creating an optimized production build...
    [PERF] Build > en > Load site > Load plugins > Init plugins - 679.05 ms - (61mb -> 110mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load blog@default > loadContent() - 7.53 ms - (110mb -> 99mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load search-algolia@default > getDefaultCodeTranslationMessages() - 8.75 ms - (110mb -> 100mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load classic@default > getDefaultCodeTranslationMessages() - 7.88 ms - (99mb -> 100mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load classic@default - 10.85 ms - (110mb -> 100mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load pages@default > loadContent() - 12.29 ms - (110mb -> 100mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load search-algolia@default - 13.29 ms - (110mb -> 100mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load pages@default - 15.22 ms - (110mb -> 101mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load blog@default > contentLoaded() - 16.14 ms - (100mb -> 107mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load blog@default - 29.50 ms - (110mb -> 107mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load docs@default > loadContent() - 3.15 seconds! - (110mb -> 388mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load docs@default > translatePluginContent() - 89.05 ms - (388mb -> 389mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load docs@default > contentLoaded() - 1.56 seconds! - (389mb -> 449mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content > Load docs@default - 4.80 seconds! - (110mb -> 449mb)
    [PERF] Build > en > Load site > Load plugins > Load plugins content - 4.80 seconds! - (110mb -> 449mb)
    [PERF] Build > en > Load site > Load plugins - 5.49 seconds! - (61mb -> 450mb)
    [PERF] Build > en > Load site > Create site files - 346.85 ms - (455mb -> 546mb)
    [PERF] Build > en > Load site - 5.86 seconds! - (61mb -> 546mb)
    [PERF] Build > en > Creating rspack bundler configs - 76.83 ms - (546mb -> 537mb)
    ● Client ██████████████████████████████████████████████████ (100%) emitting after emit                                                     
    error Command failed with signal "SIGKILL".
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    
  9. omonk commented on Dec 9, 2024

    @omonk
    Contributor

    are you seeing it while the plugin is generating the API docs or while the Docusaurus build is occurring?

    Whilst the build is occurring, generating the files is fine.

    what env are you observing the OOM error(s) in and what are the CPU/MEM specs

    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.

  10. Gijsdeman commented on Dec 10, 2024

    @Gijsdeman
    ContributorAuthor

    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!

    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.

  11. sserrata commented on Dec 10, 2024

    @sserrata
    Member

    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.

  12. omonk commented on Jun 23, 2025

    @omonk
    Contributor

    @Gijsdeman + @sserrata

    Worth having a peek at this post in Docusaurus repo - meta/docusaurus#11199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions