-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…8145) **Related issue:** - vercel/next.js#56408
- Loading branch information
Showing
27 changed files
with
14,988 additions
and
11,040 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::{path::PathBuf, sync::Arc}; | ||
|
||
use anyhow::{Context, Result}; | ||
use clap::Args; | ||
use swc_common::SourceMap; | ||
use swc_ecma_minifier::option::{CompressOptions, MangleOptions}; | ||
|
||
use crate::util::{ | ||
all_js_files, | ||
minifier::{get_minified, get_minified_with_opts}, | ||
print_js, | ||
}; | ||
|
||
/// [Experimental] Internal command to check the size difference caused by | ||
/// options. | ||
#[derive(Debug, Args)] | ||
pub struct CompareOptsCommand { | ||
pub path: PathBuf, | ||
} | ||
|
||
impl CompareOptsCommand { | ||
pub fn run(self, cm: Arc<SourceMap>) -> Result<()> { | ||
let files = all_js_files(&self.path)?; | ||
|
||
let mut default_sum = 0; | ||
let mut new_sum = 0; | ||
|
||
for file in files { | ||
let default_record = get_minified(cm.clone(), &file, true, true)?; | ||
let default_code = print_js(cm.clone(), &default_record.module, true) | ||
.context("failed to convert ast to code")?; | ||
|
||
eprintln!("default: {} bytes", default_code.as_bytes().len()); | ||
default_sum += default_code.as_bytes().len(); | ||
|
||
let new_record = get_minified_with_opts( | ||
cm.clone(), | ||
&file, | ||
Some(CompressOptions { | ||
keep_classnames: true, | ||
keep_fnames: true, | ||
..Default::default() | ||
}), | ||
Some(MangleOptions { | ||
keep_class_names: true, | ||
keep_fn_names: true, | ||
..Default::default() | ||
}), | ||
)?; | ||
let new_code = print_js(cm.clone(), &new_record.module, true) | ||
.context("failed to convert ast to code")?; | ||
|
||
eprintln!("new: {} bytes", new_code.as_bytes().len()); | ||
new_sum += new_code.as_bytes().len(); | ||
} | ||
|
||
eprintln!("default (total): {} bytes", default_sum); | ||
eprintln!("new (total): {} bytes", new_sum); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
35601e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/bugs-1
282381
ns/iter (± 8088
)284560
ns/iter (± 3390
)0.99
es/full/minify/libraries/antd
1384735159
ns/iter (± 13929748
)1383193821
ns/iter (± 13560992
)1.00
es/full/minify/libraries/d3
297732456
ns/iter (± 4893655
)295542397
ns/iter (± 3617008
)1.01
es/full/minify/libraries/echarts
1107397736
ns/iter (± 6664232
)1109847825
ns/iter (± 6939487
)1.00
es/full/minify/libraries/jquery
88852079
ns/iter (± 1369713
)89467381
ns/iter (± 771486
)0.99
es/full/minify/libraries/lodash
104605158
ns/iter (± 377377
)104195677
ns/iter (± 241040
)1.00
es/full/minify/libraries/moment
52526592
ns/iter (± 101647
)52319062
ns/iter (± 148940
)1.00
es/full/minify/libraries/react
18968471
ns/iter (± 48704
)18788957
ns/iter (± 43939
)1.01
es/full/minify/libraries/terser
229655008
ns/iter (± 974438
)230107110
ns/iter (± 944521
)1.00
es/full/minify/libraries/three
407616515
ns/iter (± 1589913
)408363859
ns/iter (± 2399893
)1.00
es/full/minify/libraries/typescript
2746192461
ns/iter (± 16143038
)2736354242
ns/iter (± 6486448
)1.00
es/full/minify/libraries/victory
585550951
ns/iter (± 5839114
)589740453
ns/iter (± 4873132
)0.99
es/full/minify/libraries/vue
126001124
ns/iter (± 432774
)125492488
ns/iter (± 193039
)1.00
es/full/codegen/es3
34564
ns/iter (± 84
)33588
ns/iter (± 151
)1.03
es/full/codegen/es5
34588
ns/iter (± 81
)33671
ns/iter (± 189
)1.03
es/full/codegen/es2015
34602
ns/iter (± 88
)33457
ns/iter (± 91
)1.03
es/full/codegen/es2016
34708
ns/iter (± 103
)33536
ns/iter (± 111
)1.03
es/full/codegen/es2017
34658
ns/iter (± 56
)33644
ns/iter (± 96
)1.03
es/full/codegen/es2018
34533
ns/iter (± 53
)33506
ns/iter (± 151
)1.03
es/full/codegen/es2019
34592
ns/iter (± 60
)33438
ns/iter (± 96
)1.03
es/full/codegen/es2020
34703
ns/iter (± 79
)33415
ns/iter (± 59
)1.04
es/full/all/es3
180175010
ns/iter (± 1267890
)176370241
ns/iter (± 1138533
)1.02
es/full/all/es5
172481674
ns/iter (± 1242607
)170723592
ns/iter (± 1033427
)1.01
es/full/all/es2015
130495456
ns/iter (± 875574
)127382600
ns/iter (± 419235
)1.02
es/full/all/es2016
128834342
ns/iter (± 1118609
)126985337
ns/iter (± 951262
)1.01
es/full/all/es2017
129391745
ns/iter (± 844362
)126074714
ns/iter (± 616334
)1.03
es/full/all/es2018
126918409
ns/iter (± 590606
)123968281
ns/iter (± 678247
)1.02
es/full/all/es2019
126524720
ns/iter (± 375931
)124023376
ns/iter (± 930039
)1.02
es/full/all/es2020
122035228
ns/iter (± 760583
)119918511
ns/iter (± 511295
)1.02
es/full/parser
585561
ns/iter (± 2693
)559131
ns/iter (± 3507
)1.05
es/full/base/fixer
20049
ns/iter (± 421
)18015
ns/iter (± 242
)1.11
es/full/base/resolver_and_hygiene
84265
ns/iter (± 257
)83844
ns/iter (± 260
)1.01
This comment was automatically generated by workflow using github-action-benchmark.