From f366d9bd7cecbc26e127887458cd63bd1e65048d Mon Sep 17 00:00:00 2001 From: Boshen Date: Sat, 13 Apr 2024 13:24:25 +0800 Subject: [PATCH] chore(minsize): remove brotlic because it takes too long to compile (#2954) --- Cargo.lock | 19 ------------------- Cargo.toml | 1 - tasks/minsize/Cargo.toml | 1 - tasks/minsize/minsize.snap | 26 ++++++++++++-------------- tasks/minsize/src/lib.rs | 24 +++++------------------- 5 files changed, 17 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74dd5aca7c57b..0df38db7d6e90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,24 +161,6 @@ dependencies = [ "syn 2.0.58", ] -[[package]] -name = "brotlic" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f552f56f302af0006c32b50bfa2bdb4696fd6ba33c3ab9f6225fefdb1efdc680" -dependencies = [ - "brotlic-sys", -] - -[[package]] -name = "brotlic-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afdec5c62bc97b56349053cf66ba503af5c2448591be61c3ad70a5f11b57e574" -dependencies = [ - "cc", -] - [[package]] name = "bstr" version = "1.9.1" @@ -1526,7 +1508,6 @@ dependencies = [ name = "oxc_minsize" version = "0.0.0" dependencies = [ - "brotlic", "flate2", "humansize", "oxc_allocator", diff --git a/Cargo.toml b/Cargo.toml index 3ecde8e3c3986..74168c48ba9a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/tasks/minsize/Cargo.toml b/tasks/minsize/Cargo.toml index b9c12a591117d..465970b429a73 100644 --- a/tasks/minsize/Cargo.toml +++ b/tasks/minsize/Cargo.toml @@ -26,4 +26,3 @@ oxc_tasks_common = { workspace = true } flate2 = { workspace = true } humansize = { workspace = true } -brotlic = { workspace = true } diff --git a/tasks/minsize/minsize.snap b/tasks/minsize/minsize.snap index 033721d10824a..6021a92635b2d 100644 --- a/tasks/minsize/minsize.snap +++ b/tasks/minsize/minsize.snap @@ -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 diff --git a/tasks/minsize/src/lib.rs b/tasks/minsize/src/lib.rs index 2ac5151b5fe3e..0f46bf3355d42 100644 --- a/tasks/minsize/src/lib.rs +++ b/tasks/minsize/src/lib.rs @@ -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}; @@ -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()?; @@ -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() -}