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

perf(gatsby-plugin-mdx): add lessBabel option, ~40% perf win #27941

Merged
merged 5 commits into from Nov 11, 2020

Conversation

pvdz
Copy link
Contributor

@pvdz pvdz commented Nov 10, 2020

This PR skips some Babel transformation steps during bootstrap in favor of less precise but very capable import/export scanning.

The mdx plugin needs to scan for the import and export symbols and paths. It is currently using Babel for this purpose. That works fine but is very very slow. We already replaced the import scanner with a regular expression approach a while back. But the export scanner had to be reverted because some sites were depending on the transformations.

So this is basically the same approach except it's tucked behind an opt-in flag. If you enable the flag, the plugin will use regular expressions to scan for export symbols and paths (which it already does for imports without flag). This will not work if you have custom syntax that affects export statements.

Currently the assumption is that any export in MDX is on a single line, or that the exported symbol is on the first line. This means that multi-line export const foo = ... is fine, since the scanner stops at the = sign. There are some limits but if you find them we can always try to support them. Just bring them to our attention.

Numbers will vary per site. I tried the very baseline gabe-fs-mdx site (available in this monorepo) at 100k pages.

Before this PR the sourcing step took 20 minutes (and before #27937 this was 50 minutes!). After this PR this step is 4 minutes!

This PR will add a lessBabel plugin option which, as you can imagine, will invoke Babel less to achieve the above projected performance improvement. At some point in the future we're likely going to make this the default, but for now we're going to look for feedback to improve the export scanner and fix forward.

Concrete numbers.

This is for gabe-fs-mdx (part of this monorepo) at 100k pages (N=100 M=8 yarn bench) on my machine under similar load:

Before #27937:

  • bootstrap: 3083s
  • page queries: 4818s
  • total build time: 77951s

Before this PR:

  • bootstrap: 1250s
  • page queries: 3207s
  • total build time: 4413s

After this PR:

  • bootstrap: 293s
  • page queries: 2929s
  • total build time: 3273s

Related PRs and issues (may not be complete)

#25734
#25757
#25975
#26002
#26003
#26004
#26202

@pvdz pvdz requested review from smthomas and a team as code owners November 10, 2020 11:40
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 10, 2020
@pvdz pvdz added topic: MDX topic: performance Related to runtime & build performance and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Nov 10, 2020
@mxstbr
Copy link
Contributor

mxstbr commented Nov 10, 2020

Once we get more feedback we can bump the major and flip the switch to make it opt-out instead. But that's future.

Love it! 👍 Thanks for tackling this 💯

laurieontech
laurieontech previously approved these changes Nov 10, 2020
Copy link
Contributor

@laurieontech laurieontech left a comment

Choose a reason for hiding this comment

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

Let's do it!

@pvdz pvdz requested a review from a team as a code owner November 11, 2020 11:26
@pvdz pvdz merged commit 3c4069f into master Nov 11, 2020
@delete-merged-branch delete-merged-branch bot deleted the mdx-less-babel branch November 11, 2020 13:15
@pvdz pvdz changed the title pref(gatsby-plugin-mdx): add lessBabel option, 40% perf win perf(gatsby-plugin-mdx): add lessBabel option, ~40% perf win Nov 11, 2020
@pvdz pvdz mentioned this pull request Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: performance Related to runtime & build performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants