Skip to content

Commit 2bdd216

Browse files
committed
perf(website): speed up 'yarn build' on multi-core machines
Process multiple files in parallel. This causes esbuild loading+building (in demo pages) to overlap with quick-lint-js loading (in error docs pages) on multi-core machines, reducing wall times for 'yarn build'. On my MacBookPro (M1) machine: Before: 24.176 seconds After but no promise-limit: 14.508 seconds After: 11.903 seconds
1 parent edb28ff commit 2bdd216

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"jsdom": "19.0.0",
1616
"markdown-it": "13.0.1",
1717
"mime": "3.0.0",
18+
"promise-limit": "^2.7.0",
1819
"quick-lint-js-node-test-runner": "../tools/quick-lint-js-node-test-runner/"
1920
},
2021
"devDependencies": {

website/run-build.mjs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import fs from "fs";
55
import path from "path";
6+
import promiseLimit from "promise-limit";
67
import { websiteConfig } from "./src/config.mjs";
78
import {
89
IndexConflictVFSError,
@@ -12,6 +13,9 @@ import {
1213
VFSDirectory,
1314
} from "./src/vfs.mjs";
1415

16+
let maxConcurrentJobs = 8;
17+
let semaphore = promiseLimit(maxConcurrentJobs);
18+
1519
async function mainAsync() {
1620
let { targetDirectory } = parseArguments(process.argv.slice(2));
1721

@@ -25,22 +29,26 @@ async function mainAsync() {
2529
async function buildDirAsync(vfs, uri, outputDirectory) {
2630
let listing = await vfs.listDirectoryAsync(uri);
2731
await fs.promises.mkdir(outputDirectory, { recursive: true });
28-
for (let childName of listing.names()) {
29-
let child = listing.get(childName);
30-
let childPath = path.join(
31-
outputDirectory,
32-
childName === "" ? "index.html" : childName
33-
);
34-
if (child instanceof VFSDirectory) {
35-
await buildDirAsync(vfs, `${uri}${childName}/`, childPath);
36-
} else if (child instanceof IndexConflictVFSError) {
37-
throw child;
38-
} else {
39-
console.log(`generating ${childPath} ...`);
40-
let data = await child.getContentsAsync();
41-
await fs.promises.writeFile(childPath, data);
42-
}
43-
}
32+
await Promise.all(
33+
listing.names().map(async (childName) => {
34+
let child = listing.get(childName);
35+
let childPath = path.join(
36+
outputDirectory,
37+
childName === "" ? "index.html" : childName
38+
);
39+
if (child instanceof VFSDirectory) {
40+
await buildDirAsync(vfs, `${uri}${childName}/`, childPath);
41+
} else if (child instanceof IndexConflictVFSError) {
42+
throw child;
43+
} else {
44+
await semaphore(async () => {
45+
console.log(`generating ${childPath} ...`);
46+
let data = await child.getContentsAsync();
47+
await fs.promises.writeFile(childPath, data);
48+
});
49+
}
50+
})
51+
);
4452
}
4553

4654
function parseArguments(args) {

website/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ [email protected]:
525525
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
526526
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==
527527

528+
promise-limit@^2.7.0:
529+
version "2.7.0"
530+
resolved "https://registry.yarnpkg.com/promise-limit/-/promise-limit-2.7.0.tgz#eb5737c33342a030eaeaecea9b3d3a93cb592b26"
531+
integrity sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw==
532+
528533
psl@^1.1.33:
529534
version "1.8.0"
530535
resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"

0 commit comments

Comments
 (0)