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(
return { result, path, page, pageKey }
}
for (let i = 0; i < exportPaths.length; i += maxConcurrency) {
const subset = exportPaths.slice(i, i + maxConcurrency)
const subsetResults = await Promise.all(
subset.map((exportPath) =>
exportPageWithRetry(
exportPath,
nextConfig.experimental.staticGenerationRetryCount ?? 1
// Prerender with a sliding window of `maxConcurrency` pages: each runner
// 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
// `exportPaths`.
const maxAttempts = nextConfig.experimental.staticGenerationRetryCount ?? 1
let nextIndex = 0
let failed = false
const runner = async () => {
while (!failed && nextIndex < exportPaths.length) {
const index = nextIndex++
try {
results[index] = await exportPageWithRetry(
exportPaths[index],
maxAttempts
)
)
)
results.push(...subsetResults)
} catch (err) {
// Stop handing out new pages once one has failed, like the previous
// batched implementation did.
failed = true
throw err
}
}
}
await Promise.all(
Array.from({ length: Math.min(maxConcurrency, exportPaths.length) }, runner)
)
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