Skip to content

Commit 9657294

Browse files
authoredJan 15, 2025··
refactor(es/minifier): Add a way to profile minifier for real-world inputs (#9881)
**Description:** I'll create a public repository that contains the inputs for the minifier using public next.js apps and some libraries
1 parent 121b5fe commit 9657294

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed
 

‎crates/swc_ecma_minifier/examples/minify-all.rs

+30-25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@ fn main() {
2626
eprintln!("Using {} files", files.len());
2727

2828
let start = Instant::now();
29+
minify_all(files);
30+
31+
eprintln!("Took {:?}", start.elapsed());
32+
}
33+
34+
/// Return the whole input files as abolute path.
35+
fn expand_dirs(dirs: Vec<String>) -> Vec<PathBuf> {
36+
dirs.into_par_iter()
37+
.map(PathBuf::from)
38+
.map(|dir| dir.canonicalize().unwrap())
39+
.flat_map(|dir| {
40+
WalkDir::new(dir)
41+
.into_iter()
42+
.filter_map(Result::ok)
43+
.filter_map(|entry| {
44+
if entry.metadata().map(|v| v.is_file()).unwrap_or(false) {
45+
Some(entry.into_path())
46+
} else {
47+
None
48+
}
49+
})
50+
.filter(|path| path.extension().map(|ext| ext == "js").unwrap_or(false))
51+
.collect::<Vec<_>>()
52+
})
53+
.collect()
54+
}
55+
56+
#[inline(never)] // For profiling
57+
fn minify_all(files: Vec<PathBuf>) {
2958
testing::run_test2(false, |cm, handler| {
3059
GLOBALS.with(|globals| {
3160
HANDLER.set(&handler, || {
@@ -91,31 +120,7 @@ fn main() {
91120
})
92121
})
93122
})
94-
.unwrap();
95-
96-
eprintln!("Took {:?}", start.elapsed());
97-
}
98-
99-
/// Return the whole input files as abolute path.
100-
fn expand_dirs(dirs: Vec<String>) -> Vec<PathBuf> {
101-
dirs.into_par_iter()
102-
.map(PathBuf::from)
103-
.map(|dir| dir.canonicalize().unwrap())
104-
.flat_map(|dir| {
105-
WalkDir::new(dir)
106-
.into_iter()
107-
.filter_map(Result::ok)
108-
.filter_map(|entry| {
109-
if entry.metadata().map(|v| v.is_file()).unwrap_or(false) {
110-
Some(entry.into_path())
111-
} else {
112-
None
113-
}
114-
})
115-
.filter(|path| path.extension().map(|ext| ext == "js").unwrap_or(false))
116-
.collect::<Vec<_>>()
117-
})
118-
.collect()
123+
.unwrap()
119124
}
120125

121126
fn print<N: swc_ecma_codegen::Node>(cm: Lrc<SourceMap>, nodes: &[N], minify: bool) -> String {

0 commit comments

Comments
 (0)
Please sign in to comment.