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

refactor(core): improve dev perf, fine-grained site reloads - part1 #9903

Merged
merged 19 commits into from
Mar 8, 2024

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Feb 29, 2024

Motivation

Adding a single character to a Markdown doc leads to a huge amount of useless CPU/IO work.

Even on a Macbook Pro M3 it's significant:

[PERF] Load - loadPlugins: 422.472ms
[PERF] Load - loadClientModules: 0.117ms
[PERF] Load - loadHtmlTags: 0.338ms
[PERF] Load - loadRoutes: 5.879ms
[PERF] Load - load codeTranslations: 26.732ms
[PERF] Load - loadSiteMetadata: 6.05ms
[PERF] Load - codegen: 22.853ms
[PERF] Loading site: 557.539ms

[PERF] Load - loadPlugins: 465.051ms
[PERF] Load - loadClientModules: 0.055ms
[PERF] Load - loadHtmlTags: 0.177ms
[PERF] Load - loadRoutes: 5.83ms
[PERF] Load - load codeTranslations: 4.533ms
[PERF] Load - loadSiteMetadata: 175.073ms
[PERF] Load - codegen: 2.892ms
[PERF] Loading site: 688.203ms

[PERF] Load - loadPlugins: 907.536ms
[PERF] Load - loadClientModules: 0.057ms
[PERF] Load - loadHtmlTags: 0.135ms
[PERF] Load - loadRoutes: 5.784ms
[PERF] Load - load codeTranslations: 52.264ms
[PERF] Load - loadSiteMetadata: 6.597ms
[PERF] Load - codegen: 2.834ms
[PERF] Loading site: 1.024s

We should optimize and only reload what is necessary.

This is also the opportunity to refactor and clean a bit our mess + instrument code to debug perf issues more easily in the future

Ideally:

  • Only a plugin should reload if a plugin file gets updated
  • Only a docs version should reload if a docs version file gets updated
  • We should bail-out from the reload process early if deepEqual(previousContent,newContent)
  • A markdown change not affecting front matter should likely not trigger any site/plugin reload, and be handled only by the Webpack dev server
  • We should avoid rewriting files that are exactly the same file as before

Note: the full optimization is going to happen in multiple PRs, and this one only implements the initial setup + the most simple optimization (still leading to great perf improvements when editing md files)

Test Plan

Unit tests + local + dogfood

The start.ts code is quite difficult to test unfortunately 😅 lots of IO/file watchers

Test links

https://deploy-preview-9903--docusaurus-2.netlify.app/

@slorber slorber added pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient. to backport This PR is planned to be backported to a stable version of Docusaurus labels Feb 29, 2024
@slorber slorber requested a review from Josh-Cena as a code owner February 29, 2024 19:06
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Feb 29, 2024
Copy link

netlify bot commented Feb 29, 2024

[V2]

Name Link
🔨 Latest commit 841c7d6
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65e0d5aaf32ae00008d3a342
😎 Deploy Preview https://deploy-preview-9903--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Copy link

github-actions bot commented Feb 29, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 60 🟢 98 🟢 96 🟢 100 🟠 88 Report
/docs/installation 🟠 59 🟢 96 🟢 100 🟢 100 🟠 88 Report
/docs/category/getting-started 🟠 76 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog 🟠 69 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 68 🟢 96 🟢 100 🟢 100 🟠 88 Report
/blog/tags/release 🟠 69 🟢 100 🟢 100 🟠 80 🟠 88 Report
/blog/tags 🟠 76 🟢 100 🟢 100 🟢 90 🟠 88 Report

Copy link

netlify bot commented Feb 29, 2024

[V2]

Name Link
🔨 Latest commit 92d68f2
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65eaf3b789ec4b00083f0938
😎 Deploy Preview https://deploy-preview-9903--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Copy link

github-actions bot commented Feb 29, 2024

Size Change: 0 B

Total Size: 992 kB

ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 75.4 kB
website/build/assets/css/styles.********.css 114 kB
website/build/assets/js/main.********.js 765 kB
website/build/index.html 37.9 kB

compressed-size-action

@slorber slorber changed the title refactor(core): improve dev perf, fine-grained site reloads refactor(core): improve dev perf, fine-grained site reloads - part1 Mar 8, 2024
@slorber slorber merged commit d02b96f into main Mar 8, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient. to backport This PR is planned to be backported to a stable version of Docusaurus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants