Skip to content

Commit 08178c5

Browse files
update bundlesize benchmark
1 parent ee96e25 commit 08178c5

3 files changed

Lines changed: 68 additions & 15 deletions

File tree

‎benchmarks/bundle-size/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Each package has `minimal` and `full` scenarios:
2121
- Start Vite scenarios use `@tanstack/<framework>-start/plugin/vite` with router code-splitting enabled.
2222
- React Start also includes Rsbuild scenarios using `@tanstack/react-start/plugin/rsbuild`.
2323
- Full-surface coverage is manually maintained (no strict export-coverage gate).
24-
- Metrics are measured from initial-load JS graph only and reported as raw/gzip/brotli bytes.
25-
- Gzip is the primary tracking signal for PR deltas and historical charting.
24+
- Primary metrics measure all emitted client JS chunks and are reported as raw/gzip/brotli bytes.
25+
- Initial-load JS graph metrics are also recorded as `initialRawBytes`, `initialGzipBytes`, and `initialBrotliBytes` for context.
26+
- Gzip for all emitted client JS is the primary tracking signal for PR deltas and historical charting.
2627

2728
## Local Run
2829

‎scripts/benchmarks/bundle-size/measure.mjs‎

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ function resolveManifestChunkKey(manifest, keyOrFile) {
168168
return undefined
169169
}
170170

171+
function isJsFile(file) {
172+
return file.endsWith('.js') || file.endsWith('.mjs')
173+
}
174+
171175
function collectInitialJsFiles(manifest, entryKey) {
172176
const visitedKeys = new Set()
173177
const files = new Set()
@@ -184,7 +188,7 @@ function collectInitialJsFiles(manifest, entryKey) {
184188
return
185189
}
186190

187-
if (typeof chunk.file === 'string' && chunk.file.endsWith('.js')) {
191+
if (typeof chunk.file === 'string' && isJsFile(chunk.file)) {
188192
files.add(chunk.file)
189193
}
190194

@@ -201,6 +205,18 @@ function collectInitialJsFiles(manifest, entryKey) {
201205
return [...files].sort()
202206
}
203207

208+
function collectAllViteJsFiles(manifest) {
209+
const files = new Set()
210+
211+
for (const chunk of Object.values(manifest)) {
212+
if (typeof chunk?.file === 'string' && isJsFile(chunk.file)) {
213+
files.add(chunk.file)
214+
}
215+
}
216+
217+
return [...files].sort()
218+
}
219+
204220
function bytesForFiles(baseDir, fileList) {
205221
let rawBytes = 0
206222
let gzipBytes = 0
@@ -461,36 +477,63 @@ function collectRsbuildInitialJsFiles(manifest, entryKey) {
461477
}
462478

463479
return files
464-
.filter(
465-
(file) =>
466-
typeof file === 'string' &&
467-
(file.endsWith('.js') || file.endsWith('.mjs')),
468-
)
480+
.filter((file) => typeof file === 'string' && isJsFile(file))
469481
.sort()
470482
}
471483

484+
function collectRsbuildAllJsFiles(manifest) {
485+
const files = new Set()
486+
487+
for (const file of manifest.allFiles || []) {
488+
if (typeof file === 'string' && isJsFile(file)) {
489+
files.add(file)
490+
}
491+
}
492+
493+
if (files.size === 0) {
494+
for (const entry of Object.values(manifest.entries || {})) {
495+
for (const file of entry?.initial?.js || []) {
496+
if (typeof file === 'string' && isJsFile(file)) {
497+
files.add(file)
498+
}
499+
}
500+
for (const file of entry?.async?.js || []) {
501+
if (typeof file === 'string' && isJsFile(file)) {
502+
files.add(file)
503+
}
504+
}
505+
}
506+
}
507+
508+
return [...files].sort()
509+
}
510+
472511
async function resolveBundleFiles({ outDir, scenario }) {
473512
if (scenario.toolchain === 'rsbuild') {
474513
const manifestInfo = await resolveRsbuildManifest(outDir, scenario.id)
475-
const jsFiles = collectRsbuildInitialJsFiles(
514+
const initialJsFiles = collectRsbuildInitialJsFiles(
476515
manifestInfo.manifest,
477516
manifestInfo.entryKey,
478517
)
518+
const jsFiles = collectRsbuildAllJsFiles(manifestInfo.manifest)
479519

480520
return {
481521
...manifestInfo,
522+
initialJsFiles,
482523
jsFiles,
483524
}
484525
}
485526

486527
const manifestInfo = await resolveManifestAndEntry(outDir, scenario.id)
487-
const jsFiles = collectInitialJsFiles(
528+
const initialJsFiles = collectInitialJsFiles(
488529
manifestInfo.manifest,
489530
manifestInfo.entryKey,
490531
)
532+
const jsFiles = collectAllViteJsFiles(manifestInfo.manifest)
491533

492534
return {
493535
...manifestInfo,
536+
initialJsFiles,
494537
jsFiles,
495538
}
496539
}
@@ -589,6 +632,10 @@ async function main() {
589632

590633
const bundleInfo = await resolveBundleFiles({ outDir, scenario })
591634
const sizes = bytesForFiles(bundleInfo.manifestOutDir, bundleInfo.jsFiles)
635+
const initialSizes = bytesForFiles(
636+
bundleInfo.manifestOutDir,
637+
bundleInfo.initialJsFiles,
638+
)
592639

593640
metrics.push({
594641
id: scenario.id,
@@ -599,7 +646,11 @@ async function main() {
599646
case: scenario.case,
600647
entryKey: bundleInfo.entryKey,
601648
manifestPath: path.relative(outDir, bundleInfo.manifestPath),
649+
initialJsFiles: bundleInfo.initialJsFiles,
602650
jsFiles: bundleInfo.jsFiles,
651+
initialRawBytes: initialSizes.rawBytes,
652+
initialGzipBytes: initialSizes.gzipBytes,
653+
initialBrotliBytes: initialSizes.brotliBytes,
603654
...sizes,
604655
})
605656
}
@@ -617,7 +668,7 @@ async function main() {
617668
name: metric.id,
618669
unit: 'bytes',
619670
value: metric.gzipBytes,
620-
extra: `raw=${metric.rawBytes}; brotli=${metric.brotliBytes}`,
671+
extra: `raw=${metric.rawBytes}; brotli=${metric.brotliBytes}; initial_gzip=${metric.initialGzipBytes}`,
621672
}))
622673

623674
const currentPath = path.join(resultsDir, 'current.json')

‎scripts/benchmarks/bundle-size/pr-report.mjs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ async function main() {
290290
current: metric.gzipBytes,
291291
raw: metric.rawBytes,
292292
brotli: metric.brotliBytes,
293+
initial: metric.initialGzipBytes,
293294
deltaCell: formatDelta(metric.gzipBytes, baselineValue),
294295
trendCell: sparkline(historySeries.slice(-args.trendPoints)),
295296
})
@@ -309,19 +310,19 @@ async function main() {
309310
}
310311
lines.push('')
311312
lines.push(
312-
'| Scenario | Current (gzip) | Delta vs baseline | Raw | Brotli | Trend |',
313+
'| Scenario | Current (gzip) | Delta vs baseline | Initial gzip | Raw | Brotli | Trend |',
313314
)
314-
lines.push('| --- | ---: | ---: | ---: | ---: | --- |')
315+
lines.push('| --- | ---: | ---: | ---: | ---: | ---: | --- |')
315316

316317
for (const row of rows) {
317318
lines.push(
318-
`| \`${row.id}\` | ${formatBytes(row.current)} | ${row.deltaCell} | ${formatBytes(row.raw)} | ${formatBytes(row.brotli)} | ${row.trendCell} |`,
319+
`| \`${row.id}\` | ${formatBytes(row.current)} | ${row.deltaCell} | ${formatBytes(row.initial)} | ${formatBytes(row.raw)} | ${formatBytes(row.brotli)} | ${row.trendCell} |`,
319320
)
320321
}
321322

322323
lines.push('')
323324
lines.push(
324-
'_Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better._',
325+
'_Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better._',
325326
)
326327

327328
const markdown = lines.join('\n') + '\n'

0 commit comments

Comments
 (0)