Skip to content

Commit

Permalink
refactor(es/minifier): Make minify-all example sequential (#9912)
Browse files Browse the repository at this point in the history
**Description:**

While profiling performance, I found that what I want is the time used by the main thread because that's the time the user will see.
  • Loading branch information
kdy1 authored Jan 21, 2025
1 parent 065baef commit 5b5c87e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions crates/swc_ecma_minifier/examples/minify-all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ use swc_ecma_transforms_base::{
fixer::{fixer, paren_remover},
resolver,
};
use swc_ecma_utils::parallel::{Parallel, ParallelExt};
use swc_ecma_utils::parallel::Parallel;
use walkdir::WalkDir;

fn main() {
let dirs = env::args().skip(1).collect::<Vec<_>>();
let files = expand_dirs(dirs);
eprintln!("Using {} files", files.len());

for i in 0..10 {
let start = Instant::now();
minify_all(&files);
eprintln!("{}: Took {:?}", i, start.elapsed());
}
let start = Instant::now();
minify_all(&files);
eprintln!("Took {:?}", start.elapsed());
}

/// Return the whole input files as abolute path.
Expand Down Expand Up @@ -85,7 +83,7 @@ fn minify_all(files: &[PathBuf]) {
GLOBALS.set(&Default::default(), || {
let mut worker = Worker::default();

worker.maybe_par(2, files, |worker, path| {
files.iter().for_each(|path| {
testing::run_test(false, |cm, handler| {
let fm = cm.load_file(path).expect("failed to load file");

Expand Down

0 comments on commit 5b5c87e

Please # to comment.