-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
perf(core): Optimize docusaurus start/serve
, fix openBrowser()
perf issue on macOS
#11007
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
packages/docusaurus/src/commands/utils/openBrowser/openBrowser.ts
Dismissed
Show dismissed
Hide dismissed
Size Change: +331 B (0%) Total Size: 11.3 MB ℹ️ View Unchanged
|
⚡️ Lighthouse report for the deploy preview of this PR
|
Size Change: +321 B (0%) Total Size: 11.7 MB ℹ️ View Unchanged
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
See jerrykingxyz#1
The Rspack team helped us identify that the
openBrowser()
util we copied from Create-React-App is not optimized:https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/openBrowser.js#L76
The Rspack compilation is delayed because it uses blocking
execSync
calls on macOS only.In this env, the util tries to run an AppleScript so that we "reuse" an existing chromium tab using
https://localhost:3000
instead of opening a new one.We'd like to keep this, since it's better DX, but not at the cost of slowing down the compiler. On my M3 Pro machine the compiler is delayed by 600ms on every
docusaurus start
ordocusaurus serve
command.The slowdown depends on the "browser position" in that array. Each browser to try takes ~150ms due to executing commands for each of them sequentially. Devs usually use "Google Chrome" so they have to try 4 browsers before the blocking shell calls stop (4 x 150ms ~= 600ms)
Moving to async non-blocking calls permits the bundler to start compiling while we are executing these commands.
I also refactored the commands so that we only run one
ps
shell command for all browsers to try, instead of running sequentialps
commands one by one.Benchmark
docusaurus start
For me (M3 / Google Chrome), 22% faster 🔥
(measuring from CLI start to first compilation + browser opened)
Note: this optimization will be even more important once we can fully leverage the Rspack persistent cache, since
openBrowser()
would become the main start bottleneck as we optimize other things.docusaurus serve
For me (M3 / Google Chrome), 30% faster 🔥
Test Plan
local benchmarks