Skip to content

Commit 4df7a8b

Browse files
committed
fix: skip esbuild's RSS metrics
1 parent 88a2210 commit 4df7a8b

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Build metrics:
138138
| Vite (Rolldown) 7.2.2 | 1893ms🥉 | 1724ms | 905MB | 2056.6kB🥈 | 633.1kB |
139139
| Rolldown 1.0.0-beta.47 | 1198ms🥇 | 1323ms🥈 | 862MB | 2074.1kB | 635.1kB |
140140
| webpack (SWC) 5.102.1 | 15453ms | 8506ms | 1730MB | 2056.9kB | 630.9kB🥉 |
141-
| esbuild 0.27.0 | 1746ms🥈 | 1643ms🥉 | 66MB🥇 | 2896.9kB | 888.7kB |
141+
| esbuild 0.27.0 | 1746ms🥈 | 1643ms🥉 | N/A | 2896.9kB | 888.7kB |
142142
| Farm 1.7.11 | 6571ms | 1923ms | 1305MB | 3822.7kB | 1330.7kB |
143143
| Parcel 2.16.1 | 11718ms | 981ms🥇 | 2028MB | 2095.4kB | 637.6kB |
144144

@@ -158,7 +158,7 @@ Build metrics:
158158
| Rsbuild 1.6.3 | 616ms | 522ms | 245MB🥉 | 1008.0kB🥈 | 270.9kB🥉 |
159159
| Rolldown 1.0.0-beta.47 | 298ms🥈 | 301ms🥈 | 220MB🥈 | 1012.2kB | 271.8kB |
160160
| webpack (SWC) 5.102.1 | 3168ms | 905ms | 678MB | 1006.2kB🥇 | 270.5kB🥇 |
161-
| esbuild 0.27.0 | 266ms🥇 | 256ms🥇 | 65MB🥇 | 1025.3kB | 276.7kB |
161+
| esbuild 0.27.0 | 266ms🥇 | 256ms🥇 | N/A | 1025.3kB | 276.7kB |
162162

163163
## Run locally
164164

scripts/benchmark.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
addRankingEmojis,
2020
shuffleArray,
2121
sleep,
22+
N_A,
2223
} from './utils.ts';
2324

2425
process.env.CASE = caseName;
@@ -115,6 +116,7 @@ interface BuildToolOptions {
115116
startedRegex: RegExp;
116117
buildScript: string;
117118
binFilePath: string;
119+
skipRss?: boolean;
118120
}
119121

120122
class BuildTool {
@@ -124,6 +126,7 @@ class BuildTool {
124126
private readonly startedRegex: RegExp;
125127
private readonly buildScript: string;
126128
private readonly binFilePath: string;
129+
public readonly skipRss: boolean;
127130

128131
constructor({
129132
name,
@@ -132,6 +135,7 @@ class BuildTool {
132135
startedRegex,
133136
buildScript,
134137
binFilePath,
138+
skipRss = false,
135139
}: BuildToolOptions) {
136140
this.name = name;
137141
this.port = port;
@@ -140,6 +144,7 @@ class BuildTool {
140144
this.buildScript = buildScript;
141145
this.binFilePath = path.join(process.cwd(), 'node_modules', binFilePath);
142146
this.hackBinFile();
147+
this.skipRss = skipRss;
143148
}
144149

145150
cleanCache(): void {
@@ -418,6 +423,8 @@ parseToolNames().forEach((name) => {
418423
startedRegex: /esbuild built in (\d+) ms/,
419424
buildScript: 'build:esbuild',
420425
binFilePath: 'esbuild/lib/main.js',
426+
// can not collect accurate RSS from esbuild
427+
skipRss: true,
421428
}),
422429
);
423430
break;
@@ -504,7 +511,7 @@ async function runDevBenchmark(
504511
const loadTime = Date.now() - start;
505512
logger.success(
506513
color.dim(buildTool.name) +
507-
' dev cold start in ' +
514+
' dev start in ' +
508515
color.green(time + loadTime + 'ms'),
509516
);
510517
metrics.devColdStart = time + loadTime;
@@ -622,7 +629,7 @@ async function runHotStartBenchmark(
622629

623630
logger.info(
624631
color.dim(
625-
'navigating to' + ` http://localhost:${buildTool.port} (hot start)`,
632+
'navigating to' + ` http://localhost:${buildTool.port} (with cache)`,
626633
),
627634
);
628635

@@ -637,7 +644,7 @@ async function runHotStartBenchmark(
637644
const loadTime = Date.now() - start;
638645
logger.success(
639646
color.dim(buildTool.name) +
640-
' dev hot start in ' +
647+
' dev start with cache in ' +
641648
color.green(time + loadTime + 'ms'),
642649
);
643650
metrics.devHotStart = time + loadTime;
@@ -647,7 +654,7 @@ async function runHotStartBenchmark(
647654
await stopServer();
648655

649656
await coolDown();
650-
logger.success(color.dim(buildTool.name) + ' dev server closed (hot start)');
657+
logger.success(color.dim(buildTool.name) + ' dev server closed (with cache)');
651658
}
652659

653660
async function runBuildBenchmark(
@@ -700,7 +707,7 @@ async function runHotBuildBenchmark(
700707

701708
logger.success(
702709
color.dim(buildTool.name) +
703-
' hot built in ' +
710+
' built with cache in ' +
704711
color.green(buildTime + 'ms'),
705712
);
706713

@@ -791,7 +798,16 @@ const getData = function (
791798
// and should be hidden
792799
return null;
793800
}
794-
const normalized = dataset.map((item) => `${item as number | string}${unit}`);
801+
802+
const normalized = dataset.map((item, index) => {
803+
if (
804+
buildTools[index].skipRss &&
805+
['devRSS', 'buildRSS'].includes(fieldName)
806+
) {
807+
return N_A;
808+
}
809+
return `${item as number | string}${unit}`;
810+
});
795811
addRankingEmojis(normalized);
796812
return normalized;
797813
};

scripts/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import fse from 'fs-extra';
33
import glob from 'fast-glob';
44
import { gzipSizeSync } from 'gzip-size';
55

6+
export const N_A = 'N/A';
7+
68
// fast-glob only accepts posix path
79
// https://github.com/mrmlnc/fast-glob#convertpathtopatternpath
810
function convertPath(path: string) {
@@ -52,7 +54,10 @@ export async function getFileSizes(targetDir: string) {
5254
export function addRankingEmojis(data: string[], sort = 'ASC') {
5355
const values = data.map((originalValue, index) => ({
5456
index,
55-
value: parseFloat(originalValue),
57+
value:
58+
originalValue === N_A
59+
? Number.MAX_SAFE_INTEGER
60+
: parseFloat(originalValue),
5661
originalValue,
5762
}));
5863

@@ -70,7 +75,9 @@ export function addRankingEmojis(data: string[], sort = 'ASC') {
7075

7176
values.forEach((item, rank) => {
7277
const emoji = rank < 3 ? emojis[rank] : '';
73-
data[item.index] = item.originalValue + emoji;
78+
if (item.originalValue !== N_A) {
79+
data[item.index] = item.originalValue + emoji;
80+
}
7481
});
7582
}
7683

0 commit comments

Comments
 (0)