Skip to content

Commit 760845a

Browse files
authored
perf(gatsby-plugin-mdx): prevent babel parse step at sourcing time (#25437)
* perf(gatsby-plugin-mdx): prevent babel parse step at sourcing time The mdx plugin was doing its default parsing step for every time it got called. At sourcing time it's only called to retrieve the import bindings and for this we can be much faster by manually processing the import statements. So that's what this does. A very simple flat no-image mdx benchmark cuts down sourcing time in half for this change. * Support multiple import statements together * Drop comments
1 parent 238d629 commit 760845a

File tree

5 files changed

+1358
-18
lines changed

5 files changed

+1358
-18
lines changed

packages/gatsby-plugin-mdx/gatsby/on-create-node.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { createContentDigest } = require(`gatsby-core-utils`)
66
const defaultOptions = require(`../utils/default-options`)
77
const createMDXNode = require(`../utils/create-mdx-node`)
88
const { MDX_SCOPES_LOCATION } = require(`../constants`)
9-
const genMDX = require(`../utils/gen-mdx`)
9+
const { findImports } = require(`../utils/gen-mdx`)
1010

1111
const contentDigest = val => createContentDigest(val)
1212

@@ -56,22 +56,19 @@ module.exports = async (
5656
createParentChildLink({ parent: node, child: mdxNode })
5757

5858
// write scope files into .cache for later consumption
59-
const { scopeImports, scopeIdentifiers } = await genMDX(
60-
{
61-
node: mdxNode,
62-
getNode,
63-
getNodes,
64-
reporter,
65-
cache,
66-
pathPrefix,
67-
options,
68-
loadNodeContent,
69-
actions,
70-
createNodeId,
71-
...helpers,
72-
},
73-
{ forceDisableCache: true }
74-
)
59+
const { scopeImports, scopeIdentifiers } = await findImports({
60+
node: mdxNode,
61+
getNode,
62+
getNodes,
63+
reporter,
64+
cache,
65+
pathPrefix,
66+
options,
67+
loadNodeContent,
68+
actions,
69+
createNodeId,
70+
...helpers,
71+
})
7572
await cacheScope({
7673
cache,
7774
scopeIdentifiers,

0 commit comments

Comments
 (0)