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
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 24, 2020
1 parent 6f17ac8 commit 3fc135e
Showing 1 changed file with 2 additions and 2 deletions.
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 3fc135e

Please sign in to comment.