cleanup logic, improve perf

pull/3386/head
Yuxuan Zhang 2 years ago
parent 1b47c8e3eb
commit 541ad0a2ca
No known key found for this signature in database
GPG Key ID: 6910B04F3351EF7D

@ -12,7 +12,14 @@ export default async function cluster(
pages: string[], pages: string[],
update: UpdateHandle update: UpdateHandle
) { ) {
const concurrency = context.config.buildConcurrency || 1 // - Each render worker could consume up to 150% of a CPU core.
// - One extra core is allocated to the main thread.
// - Excess worker will cause too much RPC workload for main thread,
// therefore harm the overall performance.
const concurrency = Math.round(
Math.max((context.config.buildConcurrency - 1) / 1.5, 1)
)
const num_tasks = pages.length const num_tasks = pages.length
const pageAlloc: TaskAllocator<string> = async () => { const pageAlloc: TaskAllocator<string> = async () => {
@ -52,12 +59,10 @@ async function renderWorker() {
const ctx = new RpcContext(parentPort!) const ctx = new RpcContext(parentPort!)
try { try {
const { const {
concurrency,
entryPath, entryPath,
pageAlloc, pageAlloc,
context context
}: { }: {
concurrency: number
entryPath: string entryPath: string
pageAlloc: TaskAllocator<string> pageAlloc: TaskAllocator<string>
context: RenderPageContext context: RenderPageContext
@ -72,7 +77,8 @@ async function renderWorker() {
await renderPage(render, page, context) await renderPage(render, page, context)
} }
} }
await Promise.all(Array.from({ length: concurrency * 4 }, () => executor())) const concurrency = Math.max(context.config.buildConcurrency, 1)
await Promise.all(Array.from({ length: concurrency }, () => executor()))
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} finally { } finally {

@ -152,7 +152,7 @@ export interface UserConfig<ThemeConfig = any>
* A lower number will reduce the memory usage but will increase the build time. * A lower number will reduce the memory usage but will increase the build time.
* *
* @experimental * @experimental
* @default 64 * @default "Number of CPU cores available"
*/ */
buildConcurrency?: number buildConcurrency?: number

Loading…
Cancel
Save