stats.toJson() blocking HMR in onDevCompileDone #5099
-
Hi all, I am trying to track compilation time across my engineering team. When I include stats.toJson() in the const rsBuild = await createRsBuild();
rsBuild.onDevCompileDone(({ stats }) => {
console.log(`Compile done in ${stats?.toJson({})?.time}ms`);
});
const rsBuildServer = await rsBuild.createDevServer();
rsBuildServer.listen() I'm on "@rsbuild/core": "1.3.11" and I've tried offloading the function to a separate worker thread, using process.nextTick, setTimeout 0, etc. but nothing has helped. I can simulate this same behavior with a promise as well. Any other things I could try here? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Resolved by creating a custom plugin and setting timestamps with onBeforeEnvironmentCompile/onAfterEnvironmentCompile. const analyticsPlugin = (): RsbuildPlugin => ({
name: 'AnalyticsPlugin',
setup(api) {
let compileStart: number;
api.onBeforeEnvironmentCompile(() => {
compileStart = Date.now();
});
api.onAfterEnvironmentCompile(({ isFirstCompile }) => {
const durationMs = Date.now() - compileStart;
});
},
}); |
Beta Was this translation helpful? Give feedback.
-
Large stats objects can introduce significant Rust-JS communication overhead. Usually we recommend getting the timing like this: const statsJson = stats.toJson({
all: false,
timings: true,
}); |
Beta Was this translation helpful? Give feedback.
Large stats objects can introduce significant Rust-JS communication overhead.
Usually we recommend getting the timing like this: