Skip to content

Commit 015dc50

Browse files
committed
Build: Report Brotli sizes in compareSize
So far, we were mostly optimizing gzipped sizes. However, using Brotli is more and more popular as all modern browsers support it and compression is much better. It makes sense to also pay attention to these numbers. The `comparseSize` version stays at `2` as this only introduces a new field without affecting existing ones. The only drawback is comparisons with branches that didnt have Brotli computed before will return `NaN`. This can be easily fixed locally by checking out the branch and running the build, but at least we don't lose gzipped sizes in the meantime. Closes jquerygh-5586 (cherry picked from commit e4b5e62)
1 parent bcfdf9a commit 015dc50

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

build/tasks/lib/compareSize.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const VERSION = 2;
99
const lastRunBranch = " last run";
1010

1111
const gzip = promisify( zlib.gzip );
12+
const brotli = promisify( zlib.brotliCompress );
1213
const exec = promisify( nodeExec );
1314

1415
async function getBranchName() {
@@ -53,7 +54,8 @@ function cacheResults( results ) {
5354
results.forEach( function( result ) {
5455
files[ result.filename ] = {
5556
raw: result.raw,
56-
gz: result.gz
57+
gz: result.gz,
58+
br: result.br
5759
};
5860
} );
5961
return files;
@@ -103,6 +105,7 @@ export async function compareSize( { cache = ".sizecache.json", files } = {} ) {
103105

104106
let rawPadLength = 0;
105107
let gzPadLength = 0;
108+
let brPadLength = 0;
106109
const results = await Promise.all(
107110
files.map( async function( filename ) {
108111

@@ -116,23 +119,27 @@ export async function compareSize( { cache = ".sizecache.json", files } = {} ) {
116119

117120
const size = Buffer.byteLength( contents, "utf8" );
118121
const gzippedSize = ( await gzip( contents ) ).length;
122+
const brotlifiedSize = ( await brotli( contents ) ).length;
119123

120124
// Add one to give space for the `+` or `-` in the comparison
121125
rawPadLength = Math.max( rawPadLength, size.toString().length + 1 );
122126
gzPadLength = Math.max( gzPadLength, gzippedSize.toString().length + 1 );
127+
brPadLength = Math.max( brPadLength, brotlifiedSize.toString().length + 1 );
123128

124-
return { filename, raw: size, gz: gzippedSize };
129+
return { filename, raw: size, gz: gzippedSize, br: brotlifiedSize };
125130
} )
126131
);
127132

128133
const sizeHeader = "raw".padStart( rawPadLength ) +
129134
"gz".padStart( gzPadLength + 1 ) +
135+
"br".padStart( brPadLength + 1 ) +
130136
" Filename";
131137

132138
const sizes = results.map( function( result ) {
133139
const rawSize = result.raw.toString().padStart( rawPadLength );
134140
const gzSize = result.gz.toString().padStart( gzPadLength );
135-
return `${ rawSize } ${ gzSize } ${ result.filename }`;
141+
const brSize = result.br.toString().padStart( brPadLength );
142+
return `${ rawSize } ${ gzSize } ${ brSize } ${ result.filename }`;
136143
} );
137144

138145
const comparisons = Object.keys( sizeCache ).sort( sortBranches ).map( function( branch ) {
@@ -148,7 +155,8 @@ export async function compareSize( { cache = ".sizecache.json", files } = {} ) {
148155

149156
const compareRaw = compareSizes( branchResult.raw, compareResult.raw, rawPadLength );
150157
const compareGz = compareSizes( branchResult.gz, compareResult.gz, gzPadLength );
151-
return `${ compareRaw } ${ compareGz } ${ filename }`;
158+
const compareBr = compareSizes( branchResult.br, compareResult.br, brPadLength );
159+
return `${ compareRaw } ${ compareGz } ${ compareBr } ${ filename }`;
152160
} );
153161

154162
return [

0 commit comments

Comments
 (0)