Skip to content

Commit

Permalink
feat(tasks/benchmark): add mangler (#8470)
Browse files Browse the repository at this point in the history
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
Boshen and autofix-ci[bot] authored Jan 14, 2025
1 parent 8fc238a commit dba054f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions tasks/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ oxc_allocator = { workspace = true, optional = true }
oxc_codegen = { workspace = true, optional = true }
oxc_isolated_declarations = { workspace = true, optional = true }
oxc_linter = { workspace = true, optional = true }
oxc_mangler = { workspace = true, optional = true }
oxc_minifier = { workspace = true, optional = true }
oxc_parser = { workspace = true, features = ["benchmarking"], optional = true }
oxc_prettier = { workspace = true, optional = true }
Expand All @@ -89,6 +90,7 @@ default = [
"dep:oxc_isolated_declarations",
"dep:oxc_linter",
"dep:oxc_minifier",
"dep:oxc_mangler",
"dep:oxc_parser",
"dep:oxc_prettier",
"dep:oxc_semantic",
Expand All @@ -115,6 +117,7 @@ semantic = ["dep:oxc_allocator", "dep:oxc_parser", "dep:oxc_semantic", "dep:oxc_
minifier = [
"dep:oxc_allocator",
"dep:oxc_minifier",
"dep:oxc_mangler",
"dep:oxc_parser",
"dep:oxc_semantic",
"dep:oxc_span",
Expand Down
28 changes: 27 additions & 1 deletion tasks/benchmark/benches/minifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use oxc_allocator::Allocator;
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
use oxc_mangler::Mangler;
use oxc_minifier::{CompressOptions, Compressor};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
Expand Down Expand Up @@ -46,5 +47,30 @@ fn bench_minifier(criterion: &mut Criterion) {
group.finish();
}

criterion_group!(minifier, bench_minifier);
fn bench_mangler(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("mangler");
for file in TestFiles::minimal().files() {
let id = BenchmarkId::from_parameter(&file.file_name);
let source_type = SourceType::from_path(&file.file_name).unwrap();
let source_text = file.source_text.as_str();
let mut allocator = Allocator::default();
group.bench_function(id, |b| {
b.iter_with_setup_wrapper(|runner| {
allocator.reset();
let program = Parser::new(&allocator, source_text, source_type).parse().program;
let (symbols, scopes) = SemanticBuilder::new()
.build(&program)
.semantic
.into_symbol_table_and_scope_tree();
runner.run(|| {
let _ =
Mangler::new().build_with_symbols_and_scopes(symbols, &scopes, &program);
});
});
});
}
group.finish();
}

criterion_group!(minifier, bench_minifier, bench_mangler);
criterion_main!(minifier);

0 comments on commit dba054f

Please sign in to comment.