Skip to content

Commit 3d100e3

Browse files
pvdzgatsbybot
and
gatsbybot
authored
perf(gatsby-plugin-mdx): Stop clobbering the same file over and over again (#27974)
* perf(gatsby-plugin-mdx): Stop clobbering the same file over and over again * Undo the await part, can be separate PR Co-authored-by: gatsbybot <[email protected]>
1 parent 5874414 commit 3d100e3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ async function onCreateNodeLessBabel(
157157
})
158158
}
159159

160+
const writeCache = new Set()
161+
160162
async function cacheScope({
161163
cache,
162164
scopeImports,
@@ -169,6 +171,16 @@ async function cacheScope({
169171
170172
export default { ${scopeIdentifiers.join(`, `)} }`
171173

174+
// Multiple files sharing the same imports/exports will lead to the same file writes.
175+
// Prevent writing the same content to the same file over and over again (reduces io pressure).
176+
// This also prevents an expensive babel step whose outcome is based on this same value
177+
if (writeCache.has(scopeFileContent)) {
178+
return
179+
}
180+
181+
// Make sure other calls see this value being processed during async time
182+
writeCache.add(scopeFileContent)
183+
172184
// if parent node is a file, convert relative imports to be
173185
// relative to new .cache location
174186
if (parentNode.internal.type === `File`) {

0 commit comments

Comments
 (0)