Skip to content

Commit

Permalink
refactor: add concurrent promise pooling for render task (#3366)
Browse files Browse the repository at this point in the history
fixes #3362
closes #3285

---------

Co-authored-by: Yuxuan Zhang <[email protected]>
Co-authored-by: Divyansh Singh <[email protected]>
Co-authored-by: David Silva <[email protected]>
  • Loading branch information
4 people authored Dec 26, 2023
1 parent f4d4280 commit 6dac9a4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"nanoid": "^5.0.4",
"npm-run-all": "^4.1.5",
"ora": "^8.0.1",
"p-map": "^7.0.0",
"path-to-regexp": "^6.2.1",
"picocolors": "^1.0.0",
"pkg-dir": "^8.0.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions src/node/build/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createHash } from 'crypto'
import fs from 'fs-extra'
import { createRequire } from 'module'
import pMap from 'p-map'
import path from 'path'
import { packageDirectorySync } from 'pkg-dir'
import { rimraf } from 'rimraf'
Expand Down Expand Up @@ -106,23 +107,23 @@ export async function build(
}
}

await Promise.all(
['404.md', ...siteConfig.pages]
.map((page) => siteConfig.rewrites.map[page] || page)
.map((page) =>
renderPage(
render,
siteConfig,
page,
clientResult,
appChunk,
cssChunk,
assets,
pageToHashMap,
metadataScript,
additionalHeadTags
)
await pMap(
['404.md', ...siteConfig.pages],
async (page) => {
await renderPage(
render,
siteConfig,
siteConfig.rewrites.map[page] || page,
clientResult,
appChunk,
cssChunk,
assets,
pageToHashMap,
metadataScript,
additionalHeadTags
)
},
{ concurrency: siteConfig.buildConcurrency }
)
})

Expand Down
3 changes: 2 additions & 1 deletion src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export async function resolveConfig(
transformPageData: userConfig.transformPageData,
rewrites,
userConfig,
sitemap: userConfig.sitemap
sitemap: userConfig.sitemap,
buildConcurrency: userConfig.buildConcurrency ?? 64
}

// to be shared with content loaders
Expand Down
10 changes: 10 additions & 0 deletions src/node/siteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ export interface UserConfig<ThemeConfig = any>
*/
useWebFonts?: boolean

/**
* This option allows you to configure the concurrency of the build.
* A lower number will reduce the memory usage but will increase the build time.
*
* @experimental
* @default 64
*/
buildConcurrency?: number

/**
* @experimental
*
Expand Down Expand Up @@ -240,4 +249,5 @@ export interface SiteConfig<ThemeConfig = any>
}
logger: Logger
userConfig: UserConfig
buildConcurrency: number
}

0 comments on commit 6dac9a4

Please sign in to comment.