Skip to content

Commit ed7cc2f

Browse files
authored
fix: prevent O(n²) memory allocation in content lookup map generation (#14973)
* refactor: simplify lookup map entry assignment logic * chore: add changeset for lookup map OOM fix
1 parent c016f10 commit ed7cc2f

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

.changeset/fix-lookup-map-oom.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Fixes performance regression and OOM errors when building medium-sized blogs with many content entries. Replaced O(n²) object spread pattern with direct mutation in `generateLookupMap`.

packages/astro/src/content/vite-plugin-content-virtual-mod.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,22 +355,12 @@ async function generateLookupMap({ settings, fs }: { settings: AstroSettings; fs
355355
: undefined,
356356
});
357357
}
358-
lookupMap[collection] = {
359-
type: 'content',
360-
entries: {
361-
...lookupMap[collection]?.entries,
362-
[slug]: rootRelativePath(root, filePath),
363-
},
364-
};
358+
lookupMap[collection] ??= { type: 'content', entries: {} };
359+
lookupMap[collection].entries[slug] = rootRelativePath(root, filePath);
365360
} else {
366361
const id = getDataEntryId({ entry: pathToFileURL(filePath), contentDir, collection });
367-
lookupMap[collection] = {
368-
type: 'data',
369-
entries: {
370-
...lookupMap[collection]?.entries,
371-
[id]: rootRelativePath(root, filePath),
372-
},
373-
};
362+
lookupMap[collection] ??= { type: 'data', entries: {} };
363+
lookupMap[collection].entries[id] = rootRelativePath(root, filePath);
374364
}
375365
}),
376366
);

0 commit comments

Comments
 (0)