From 95562f24eb92d6045204b41b52a3a542adf1114f Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 23 Sep 2026 16:23:34 +0800 Subject: [PATCH] perf: skip unused HMR in warm timing sessions --- scripts/benchmark.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts index 1f24f3629..3ddb78a8e 100644 --- a/scripts/benchmark.ts +++ b/scripts/benchmark.ts @@ -791,17 +791,21 @@ async function runDevSession( return duration; }); }; + // Warm timing sessions only measure startup; memory sessions need HMR load. + const runHmr = cache === 'cold' || measurement === 'memory'; const hmrTimes: number[] = []; - for (let update = 0; update < 10; update++) { - const file = files[update % 2]; - const marker = `benchmark-hmr-${cache}-${update}`; - hmrTimes.push( - await updateModule( - file.path, - `${file.baseline}\nconsole.log(${JSON.stringify(marker)}, Date.now());\n`, - marker, - ), - ); + if (runHmr) { + for (let update = 0; update < 10; update++) { + const file = files[update % 2]; + const marker = `benchmark-hmr-${cache}-${update}`; + hmrTimes.push( + await updateModule( + file.path, + `${file.baseline}\nconsole.log(${JSON.stringify(marker)}, Date.now());\n`, + marker, + ), + ); + } } if (measurement === 'timing' && cache === 'cold') { metrics.rootHmr = median(hmrTimes.filter((_, index) => index % 2 === 0)); @@ -831,8 +835,10 @@ async function runDevSession( } // Measurement is over. Restore the exact baseline while the server is // alive, await each rebuild, then let graceful shutdown flush the cache. - for (const file of files) - await updateModule(file.path, file.baseline, file.marker); + if (runHmr) { + for (const file of files) + await updateModule(file.path, file.baseline, file.marker); + } details = { ...details, succeeded: true }; } catch (error) { command.error ??= String(error);