perf(gatsby-plugin-mdx): add lessBabel
option, ~40% perf win
#27941
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.
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-lineexport 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:
Before this PR:
After this PR:
Related PRs and issues (may not be complete)
#25734
#25757
#25975
#26002
#26003
#26004
#26202