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): Stop clobbering the same file over and over again (#27974) #28874

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/gatsby-plugin-mdx/gatsby/on-create-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ async function onCreateNodeLessBabel(
})
}

const writeCache = new Set()

async function cacheScope({
cache,
scopeImports,
Expand All @@ -169,6 +171,16 @@ async function cacheScope({
export default { ${scopeIdentifiers.join(`, `)} }`

// Multiple files sharing the same imports/exports will lead to the same file writes.
// Prevent writing the same content to the same file over and over again (reduces io pressure).
// This also prevents an expensive babel step whose outcome is based on this same value
if (writeCache.has(scopeFileContent)) {
return
}

// Make sure other calls see this value being processed during async time
writeCache.add(scopeFileContent)

// if parent node is a file, convert relative imports to be
// relative to new .cache location
if (parentNode.internal.type === `File`) {
Expand Down