Unverified Commit c2f6c631 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

perf(export): use sliding concurrency pool for prerendering

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent caa60a93
...@@ -565,21 +565,34 @@ export async function exportPages( ...@@ -565,21 +565,34 @@ export async function exportPages(
return { result, path, page, pageKey } return { result, path, page, pageKey }
} }
for (let i = 0; i < exportPaths.length; i += maxConcurrency) { // Prerender with a sliding window of `maxConcurrency` pages: each runner
const subset = exportPaths.slice(i, i + maxConcurrency) // picks up the next path as soon as its current one finishes, so a single
// slow page doesn't hold back the other slots. Results keep the order of
const subsetResults = await Promise.all( // `exportPaths`.
subset.map((exportPath) => const maxAttempts = nextConfig.experimental.staticGenerationRetryCount ?? 1
exportPageWithRetry( let nextIndex = 0
exportPath, let failed = false
nextConfig.experimental.staticGenerationRetryCount ?? 1 const runner = async () => {
while (!failed && nextIndex < exportPaths.length) {
const index = nextIndex++
try {
results[index] = await exportPageWithRetry(
exportPaths[index],
maxAttempts
) )
) } catch (err) {
) // Stop handing out new pages once one has failed, like the previous
// batched implementation did.
results.push(...subsetResults) failed = true
throw err
}
}
} }
await Promise.all(
Array.from({ length: Math.min(maxConcurrency, exportPaths.length) }, runner)
)
return results return results
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment