From 8a4b50820d6d584e6111c11080bb7394898ae0f1 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 10 Sep 2026 08:48:02 +0800 Subject: [PATCH] perf(core): overlap file reads within ast generator chunks --- packages/core/src/generators/ast/generate.mjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/generators/ast/generate.mjs b/packages/core/src/generators/ast/generate.mjs index 81ef3f4ca..a25a8b35f 100644 --- a/packages/core/src/generators/ast/generate.mjs +++ b/packages/core/src/generators/ast/generate.mjs @@ -51,10 +51,15 @@ const isMdxFile = (path, content) => { export async function processChunk(inputSlice, itemIndices) { const filePaths = itemIndices.map(idx => inputSlice[idx]); + // Reads overlap within the chunk; parsing below stays sequential. + const contents = await Promise.all( + filePaths.map(([path]) => readFile(path, 'utf-8')) + ); + const results = []; - for (const [path, parent] of filePaths) { - const content = await readFile(path, 'utf-8'); + for (const [i, [path, parent]] of filePaths.entries()) { + const content = contents[i]; const mdx = isMdxFile(path, content);