Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build performance optimizations for projects with large sidebars #2252

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented Aug 22, 2024

Description

This PR is a draft experimenting with a new approach to fix #2215 by caching generated sidebars per locale to avoid regenerating them for each page during the build process.

A few details about the approach:

  • It's using a basic Map at the moment.
    • I still want to try this approach against the SSR PR and maybe test with an LRU instead.
  • The approach is used for the docs content collections pages and <StarlightPage> not specifying a custom sidebar (which means the sidebar generated based on the global sidebar config is used).
    • Using the same approach for <StarlightPage> with a custom sidebar would probably require a hash of the custom sidebar config so I decided to keep it simple for now and it's not required to get an idea of the potential performance improvements (there is also no guarantee that generating such a hash would not kill the performance improvements from the caching).

Here are some benchmarks I ran on my machine:

Starlight Docs

  • Images are cached from a previous run.

Before:

❯ hyperfine --runs 5 'pnpm build'
Benchmark 1: pnpm build
  Time (mean ± σ):     23.290 s ±  0.592 s    [User: 34.546 s, System: 3.046 s]
  Range (min … max):   22.431 s … 23.840 s    5 runs

After:

❯ hyperfine --runs 5 'pnpm build'
Benchmark 1: pnpm build
  Time (mean ± σ):     22.000 s ±  0.886 s    [User: 32.500 s, System: 2.769 s]
  Range (min … max):   21.124 s … 23.097 s    5 runs

Cloudflare Docs (no patch)

  • Images are cached from a previous run.
  • Default Starlight with the changes from this PR applied without the Starlight patch that is applied to the Cloudflare docs.
  • astro check has been removed from the build npm script as it's not really relevant for this benchmark.

Before:

❯ hyperfine --runs 5 'npm run build'
Benchmark 1: npm run build
  Time (mean ± σ):     363.060 s ±  2.154 s    [User: 394.678 s, System: 24.588 s]
  Range (min … max):   360.170 s … 366.090 s    5 runs

After:

❯ hyperfine --runs 5 'npm run build'
Benchmark 1: npm run build
  Time (mean ± σ):     230.533 s ±  2.276 s    [User: 264.999 s, System: 22.543 s]
  Range (min … max):   228.171 s … 233.879 s    5 runs

Cloudflare Docs (with patch)

  • Images are cached from a previous run.
  • Starlight using the changes from this PR and an updated version of the Starlight patch that is applied to the Cloudflare docs (updated so that the cache of intermediate sidebars is keyed by locale + current section instead of just locale).
  • astro check has been removed from the build npm script as it's not really relevant for this benchmark.

Before:

❯ hyperfine --runs 5 'npm run build'
Benchmark 1: npm run build
  Time (mean ± σ):     210.619 s ±  2.512 s    [User: 240.743 s, System: 22.913 s]
  Range (min … max):   208.476 s … 214.525 s    5 runs

After:

❯ hyperfine --runs 5 'npm run build'
Benchmark 1: npm run build
  Time (mean ± σ):     200.607 s ±  3.295 s    [User: 229.740 s, System: 21.582 s]
  Range (min … max):   196.067 s … 204.917 s    5 runs

A few interesting points:

  • For the Starlight Docs, the improvement is not really significant but it's expected as it's mostly targeting sites with large sidebars.
  • For the Cloudflare Docs with their current patch updated, the improvement is also not that huge but I think it's also expected as their current patch already trimmed down the number of entries generated for the sidebars a lot.
  • For the Cloudflare Docs without the patch, the improvement is a bit more interesting, especially considering that most people will not have similar use cases and optimizations in a custom patch.

Copy link

changeset-bot bot commented Aug 22, 2024

⚠️ No Changeset found

Latest commit: b33291c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Aug 22, 2024
Copy link

netlify bot commented Aug 22, 2024

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit b33291c
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/6718ed344e206600087c9003
😎 Deploy Preview https://deploy-preview-2252--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

* main: (240 commits)
  i18n(de): update some files for consistency in German language (withastro#2502)
  i18n(zh-cn): Update `plugins.mdx` (withastro#2501)
  i18n(de): translate guides/pages (withastro#2469)
  i18n(de): translate components/code (withastro#2457)
  i18n(de): translate components/using-components (withastro#2455)
  [ci] format
  i18n(de): translate guides/site-search (withastro#2481)
  i18n(de): update translation guides/customization (withastro#2475)
  i18n(de): update translation manual-setup (withastro#2479)
  i18n(de): update translation reference/overrides (withastro#2480)
  i18n(de): translate reference/plugins (withastro#2464)
  i18n(de): update translation guides/authoring-content (withastro#2458)
  [ci] format
  i18n(de): update translation reference/configuration (withastro#2459)
  i18n(de): update translation reference/frontmatter (withastro#2470)
  [ci] format
  i18n(de): update translation guides/i18n (withastro#2476)
  i18n(de): update `resources/plugins.mdx` (withastro#2498)
  i18n(ko-KR): update `plugins.mdx` (withastro#2500)
  i18n(fr): Update `resources/plugins` from withastro#2493 (withastro#2496)
  ...
@HiDeoo HiDeoo marked this pull request as ready for review October 23, 2024 12:38
@HiDeoo
Copy link
Member Author

HiDeoo commented Oct 23, 2024

Undrafting the PR as I've been playing quite a bit with the changes and didn't see any downside to the current approach. I still want to do a little bit of play-testing with some SSR scenarios but I thought I might as well undraft the PR before I forget as usual and in case some users want to provide some feedback in the meantime.

@delucis delucis added the 🌟 minor Change that triggers a minor release label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package 🌟 minor Change that triggers a minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Large sidebars (i.e autogenerating all folders) causes build slowdowns due to repeated getSidebar calls
2 participants