Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): Use getNodesByType for plugin transformation (#…
Browse files Browse the repository at this point in the history
…22555)

Since getSourcePluginsAsRemarkPlugins is called on
every MDX file, the getNodes call became expensive
at scale with thousands of MDX files.

This was encountered when attempting to find
underlying issues for #22521. @pvdz had a hunch that
node traversal may be a culprit. This doesn't fully
address all underlying performance issues but
is a quick win.

8k MDX pages: 440s => 350s
16k MDX pages: 1100s => 750s
  • Loading branch information
johno committed Mar 25, 2020
1 parent b907bda commit 63d091a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-mdx/loaders/mdx-loader.test.js
Expand Up @@ -74,7 +74,10 @@ describe(`mdx-loader`, () => {
}
},
query: {
getNodes() {
getNodes(_type) {
return fixtures.map(([, node]) => node)
},
getNodesByType(_type) {
return fixtures.map(([, node]) => node)
},
pluginOptions: {},
Expand Down
Expand Up @@ -13,7 +13,7 @@ module.exports = async function getSourcePluginsAsRemarkPlugins({
gatsbyRemarkPlugins,
mdxNode,
getNode,
getNodes,
getNodesByType,
reporter,
cache,
pathPrefix,
Expand All @@ -39,7 +39,7 @@ module.exports = async function getSourcePluginsAsRemarkPlugins({
}
}

fileNodes = getNodes().filter(n => n.internal.type === `File`)
fileNodes = getNodesByType(`File`)

// return list of remarkPlugins
const userPlugins = gatsbyRemarkPlugins
Expand Down

0 comments on commit 63d091a

Please sign in to comment.