Skip to content

Speed up Docusaurus build#146

Open
Miggets7 wants to merge 8 commits intomainfrom
feature/speed-up-docusaurus-build
Open

Speed up Docusaurus build#146
Miggets7 wants to merge 8 commits intomainfrom
feature/speed-up-docusaurus-build

Conversation

@Miggets7
Copy link
Contributor

@Miggets7 Miggets7 commented Mar 4, 2026

Summary

  • Rspack + SWC: Replace webpack/Babel with Rspack bundler and SWC via @docusaurus/faster — includes MDX cross-compiler cache, Lightning CSS, multi-threaded SSG, and persistent build cache
  • Dev-time version limiting: Only build "current" version during local development (yarn start), so the dev server starts in seconds instead of minutes
  • CI improvements: Add Docusaurus build cache step and upgrade Node from 20 to 24
  • Image compression: Compress ~470 PNG images with pngquant (65-80% quality), reducing repository size and speeding up checkout/deploy
  • Remove babel.config.js: No longer needed with SWC

All 18 versions and all API language tabs remain in production builds.

Test plan

  • yarn start — dev server starts quickly with only "current" version
  • yarn build — full production build succeeds with all 18 versions
  • REST API docs render correctly (code samples, schemas, try-it-out)
  • Version dropdown works in production build
  • Compressed images display correctly
  • CI build passes; verify cache is hit on second run
  • If Rspack issues arise with OpenAPI plugin, individual experimental_faster flags can be toggled off

Miggets7 added 2 commits March 4, 2026 15:01
- Add @docusaurus/faster for Rspack bundler, SWC transpilation/minification,
  Lightning CSS, MDX cross-compiler cache, and multi-threaded SSG
- Limit dev server to current version only for faster local development
- Remove babel.config.js (replaced by SWC)
- Add Docusaurus build cache step in CI workflow
- Upgrade Node from 20 to 24 in CI
- Compress 138 large PNG images with pngquant (65-80% quality)
330 additional images compressed (quality 65-80%, skip-if-larger).
Reduces repository size and speeds up checkout, CI, and deployment.
@Miggets7 Miggets7 requested review from denniskuijs and wborn and removed request for denniskuijs March 4, 2026 14:15
Miggets7 added 6 commits March 4, 2026 15:16
Required by org policy that all actions must be pinned to a
full-length commit SHA.
Rspack (which replaced webpack) runs as native Rust code outside the
Node heap. With 6 GB allocated to Node, peak memory reached 8.3 GB
total (Node + Rspack native), exceeding the 7 GB runner limit and
causing the Linux OOM killer to terminate the build. Setting the heap
to 4 GB leaves ~3 GB for Rspack and the OS.
The Rspack build peaks at ~8 GB, exceeding the 7 GB runner limit.
Adding 10 GB swap prevents the Linux OOM killer from terminating the
build process.
GitHub runners already have a 4 GB /swapfile in use. Disable it first,
then recreate at 14 GB to give enough headroom for the Rspack build.
With 14 GB swap as safety net, the 6 GB heap allows V8 to GC less
aggressively, improving build performance. Brief memory peaks above
7 GB will use swap instead of crashing.
@wborn wborn requested a review from Copilot March 5, 2026 10:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improve Docusaurus build performance by enabling the @docusaurus/faster toolchain, limiting dev-time version builds, and optimizing CI with caching and a newer Node runtime.

Changes:

  • Enable @docusaurus/faster / Rspack + SWC via future.experimental_faster flags
  • In dev, build only the current docs version to speed up yarn start
  • Update CI to use Node 24, add swap space, and cache Docusaurus build artifacts

Reviewed changes

Copilot reviewed 4 out of 473 changed files in this pull request and generated 3 comments.

File Description
package.json Adds @docusaurus/faster dependency to support faster build toolchain
docusaurus.config.ts Enables faster toolchain flags and limits versions in development builds
babel.config.js Removes Babel config no longer needed with SWC
.github/workflows/ci_cd.yml Adds swap, updates Node version, and introduces build caching
Comments suppressed due to low confidence (1)

package.json:23

  • The new dependency uses a caret range (^3.9.2) while other Docusaurus packages in this file appear to be pinned more tightly (e.g., @docusaurus/theme-mermaid: 3.9.2). To reduce the risk of version skew between tightly-coupled Docusaurus packages, consider pinning @docusaurus/faster to the same exact version.
    "@docusaurus/faster": "^3.9.2",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +58 to +60
...(process.env.NODE_ENV === 'development' && {
onlyIncludeVersions: ['current'],
}),
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This object spread pattern can fail TypeScript type-checking with errors like 'Spread types may only be created from object types' because the expression is false | { ... }. Prefer a ternary that always returns an object (e.g., condition ? { ... } : {}) to keep the config TS-safe.

Suggested change
...(process.env.NODE_ENV === 'development' && {
onlyIncludeVersions: ['current'],
}),
...(process.env.NODE_ENV === 'development'
? { onlyIncludeVersions: ['current'] }
: {}),

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +34
# Resize existing swap from default 4 GB to 14 GB
sudo swapoff /swapfile || true
sudo rm -f /swapfile
sudo fallocate -l 14G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocating a fixed 14G swapfile can fail on ubuntu-latest if there isn’t enough free disk after checkout and dependency install (leading to workflow failures). Consider sizing swap dynamically based on available disk space, or using a smaller/default swap increase to reduce the chance of fallocate failing.

Suggested change
# Resize existing swap from default 4 GB to 14 GB
sudo swapoff /swapfile || true
sudo rm -f /swapfile
sudo fallocate -l 14G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Resize existing swap from default 4 GB to up to 14 GB, depending on free disk space
sudo swapoff /swapfile || true
sudo rm -f /swapfile
# Determine available disk space (in MiB) on the root filesystem
AVAIL_MB=$(df -m / | awk 'NR==2 {print $4}')
# Leave 2 GiB free to avoid filling the disk
TARGET_MB=$((AVAIL_MB - 2048))
# Cap swap size at 14 GiB (14336 MiB)
MAX_SWAP_MB=14336
if [ "$TARGET_MB" -gt "$MAX_SWAP_MB" ]; then
TARGET_MB=$MAX_SWAP_MB
fi
# Ensure a reasonable minimum of 4 GiB (4096 MiB)
MIN_SWAP_MB=4096
if [ "$TARGET_MB" -lt "$MIN_SWAP_MB" ]; then
echo "Not enough free disk space to safely allocate ${MIN_SWAP_MB} MiB swap; skipping swap resize."
else
echo "Allocating ${TARGET_MB} MiB of swap space..."
sudo fallocate -l "${TARGET_MB}M" /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
fi

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +58
- name: Cache Docusaurus build
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
.docusaurus
node_modules/.cache
key: docusaurus-${{ runner.os }}-${{ hashFiles('yarn.lock', 'docusaurus.config.ts', 'versions.json') }}
restore-keys: |
docusaurus-${{ runner.os }}-
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache key doesn’t include the Node version. If the Node version changes (or differs across runners), restoring .docusaurus / node_modules/.cache across Node versions can cause flaky builds or hard-to-debug bundler cache issues. Consider incorporating node-version (and potentially Docusaurus version) into the cache key.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants