Skip to content

Commit

Permalink
fix: watching.close() is slow
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed May 30, 2024
1 parent 140b621 commit 9c27f63
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bench.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const isScheduled = !!process.env.SCHEDULED_JOB;

// HMR will run 10 times in build plugin, so we should not start multiple instances of Rspack.
// However, we still need to run multiple instances of Rspack when executing scheduled tasks for longer runtimes.
const hmrRuns = isScheduled ? 10 : 1;
const hmrRuns = isScheduled ? 10 : 5;

export default {
jobs: [
Expand Down
19 changes: 5 additions & 14 deletions lib/scenarios/build-plugin.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ module.exports = class BuildPlugin {
compiler.hooks.watchRun.tap("BuildPlugin", () => {
isWatching = true;
});
(compiler.hooks.afterDone || compiler.hooks.done).tap("BuildPlugin", () => {
setTimeout(() => {
if (counter === WARMUP_BUILDS) console.log("#!# start");
if (isWatching && counter <= TOTAL_BUILDS) console.log("#!# next");
}, 10);
compiler.hooks.afterDone.tap("BuildPlugin", () => {
if (counter === WARMUP_BUILDS) console.log("#!# start");
if (isWatching && counter <= TOTAL_BUILDS) console.log("#!# next");
});
compiler.hooks.done.tap("BuildPlugin", stats => {
if (isWatching) {
counter++;
if (counter <= WARMUP_BUILDS) return;
if (counter > TOTAL_BUILDS) {
if (compiler.watching) {
compiler.watching.close();
} else {
process.nextTick(() => process.exit(0));
}
process.nextTick(() => process.exit(0));
}
}
const { logging, time } = stats.toJson({
Expand Down Expand Up @@ -69,10 +63,7 @@ module.exports = class BuildPlugin {
if (type !== "time") return;
const ms = args[1] * 1000 + args[2] / 1000000;
console.log(
`#!# ${name}.${args[0].replace(
/restore cache content \d.+$/,
"restore cache content"
)} = ${ms}`
`#!# ${name}.${args[0].replace(/restore cache content \d.+$/, "restore cache content")} = ${ms}`
);
};
}
Expand Down
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 9c27f63

Please sign in to comment.