Skip to content

Commit

Permalink
chore(minsize): remove brotlic because it takes too long to compile (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Apr 13, 2024
1 parent adabbac commit f366d9b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 54 deletions.
19 changes: 0 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ wasm-bindgen = "0.2"
serde-wasm-bindgen = "0.6.5"
handlebars = "5.1.2"
base64 = "0.22.0"
brotlic = "0.8.2"
compact_str = "0.7.1"
console = "0.15.8"
encoding_rs = "0.8.33"
Expand Down
1 change: 0 additions & 1 deletion tasks/minsize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ oxc_tasks_common = { workspace = true }
flate2 = { workspace = true }

humansize = { workspace = true }
brotlic = { workspace = true }
26 changes: 12 additions & 14 deletions tasks/minsize/minsize.snap
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
Original -> Minified -> Gzip Brotli
72.14 kB -> 24.35 kB -> 8.73 kB 7.64 kB react.development.js
Original -> Minified -> Gzip
72.14 kB -> 39.58 kB -> 10.83 kB react.development.js

173.90 kB -> 61.88 kB -> 19.57 kB 17.75 kB moment.js
173.90 kB -> 95.37 kB -> 24.37 kB moment.js

287.63 kB -> 93.08 kB -> 32.33 kB 29.27 kB jquery.js
287.63 kB -> 140.16 kB -> 39.82 kB jquery.js

342.15 kB -> 123.08 kB -> 44.99 kB 39.66 kB vue.js
342.15 kB -> 189.85 kB -> 55.32 kB vue.js

544.10 kB -> 75.67 kB -> 26.10 kB 23.20 kB lodash.js
544.10 kB -> 144.63 kB -> 35.31 kB lodash.js

555.77 kB -> 275.06 kB -> 91.42 kB 76.82 kB d3.js
555.77 kB -> 390.47 kB -> 102.94 kB d3.js

977.19 kB -> 458.45 kB -> 123.87 kB 107.24 kB bundle.min.js
977.19 kB -> 603.47 kB -> 138.53 kB bundle.min.js

1.25 MB -> 677.68 kB -> 166.56 kB 134.53 kB three.js
1.25 MB -> 929.41 kB -> 189.96 kB three.js

2.14 MB -> 743.82 kB -> 181.81 kB 138.82 kB victory.js
2.14 MB -> 1.41 MB -> 217.64 kB victory.js

3.20 MB -> 1.03 MB -> 332.69 kB 269.01 kB echarts.js
3.20 MB -> 1.73 MB -> 427.25 kB echarts.js

6.69 MB -> 2.42 MB -> 502.89 kB 394.38 kB antd.js

10.82 MB -> 3.52 MB -> 902.42 kB 693.05 kB typescript.js
10.82 MB -> 5.71 MB -> 1.10 MB typescript.js

24 changes: 5 additions & 19 deletions tasks/minsize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
io::{self, Write},
};

use brotlic::{BlockSize, BrotliEncoderOptions, CompressorWriter, Quality, WindowSize};
use flate2::{write::GzEncoder, Compression};
use humansize::{format_size, DECIMAL};

Expand All @@ -29,27 +28,28 @@ pub fn run() -> Result<(), io::Error> {

let mut out = String::new();
out.push_str(&format!(
"{:width$} -> {:width$} -> {:width$}",
"{:width$} -> {:width$} -> {:width$}\n",
"Original",
"Minified",
"Gzip",
width = 10
));
out.push_str(&format!(" {:width$}\n", "Brotli", width = 10));

for file in files.files() {
let minified = minify_twice(file);
let s = format!(
"{:width$} -> {:width$} -> {:width$} {:width$} {}\n\n",
"{:width$} -> {:width$} -> {:width$} {:width$}\n\n",
format_size(file.source_text.len(), DECIMAL),
format_size(minified.len(), DECIMAL),
format_size(gzip_size(&minified), DECIMAL),
format_size(brotli_size(&minified), DECIMAL),
&file.file_name,
width = 10
);
out.push_str(&s);
}

println!("{out}");

let mut snapshot = File::create(path)?;
snapshot.write_all(out.as_bytes())?;
snapshot.flush()?;
Expand Down Expand Up @@ -82,17 +82,3 @@ fn gzip_size(s: &str) -> usize {
let s = e.finish().unwrap();
s.len()
}

fn brotli_size(s: &str) -> usize {
let encoder = BrotliEncoderOptions::new()
.quality(Quality::best())
.window_size(WindowSize::best())
.block_size(BlockSize::best())
.build()
.unwrap();

let mut e = CompressorWriter::with_encoder(encoder, Vec::new());
e.write_all(s.as_bytes()).unwrap();
let s = e.into_inner().unwrap();
s.len()
}

0 comments on commit f366d9b

Please sign in to comment.