mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
perf(minifier): only visit arrow expression after dropping console.log (#4677)
This commit is contained in:
parent
4a5695416d
commit
0f5e982d19
4 changed files with 11 additions and 39 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1367,7 +1367,6 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"criterion2",
|
||||
"oxc_allocator",
|
||||
"oxc_ast",
|
||||
"oxc_codegen",
|
||||
"oxc_isolated_declarations",
|
||||
"oxc_linter",
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ impl<'a> VisitMut<'a> for RemoveSyntax<'a> {
|
|||
self.strip_parenthesized_expression(expr);
|
||||
self.compress_console(expr);
|
||||
walk_mut::walk_expression(self, expr);
|
||||
}
|
||||
|
||||
fn visit_arrow_function_expression(&mut self, expr: &mut ArrowFunctionExpression<'a>) {
|
||||
self.recover_arrow_expression_after_drop_console(expr);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,13 +71,9 @@ impl<'a> RemoveSyntax<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn recover_arrow_expression_after_drop_console(&self, expr: &mut Expression<'a>) {
|
||||
if self.options.drop_console {
|
||||
if let Expression::ArrowFunctionExpression(arrow_expr) = expr {
|
||||
if arrow_expr.expression && arrow_expr.body.is_empty() {
|
||||
arrow_expr.expression = false;
|
||||
}
|
||||
}
|
||||
fn recover_arrow_expression_after_drop_console(&self, expr: &mut ArrowFunctionExpression<'a>) {
|
||||
if self.options.drop_console && expr.expression && expr.body.is_empty() {
|
||||
expr.expression = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,10 +65,9 @@ name = "parser_napi"
|
|||
harness = false
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
# All `oxc_*` dependencies optional as on CI we build each benchmark separately
|
||||
# with only the crates it needs, to speed up the builds
|
||||
oxc_ast = { workspace = true, optional = true }
|
||||
[dependencies]
|
||||
oxc_allocator = { workspace = true, optional = true }
|
||||
oxc_linter = { workspace = true, optional = true }
|
||||
oxc_minifier = { workspace = true, optional = true }
|
||||
|
|
@ -114,7 +113,6 @@ transformer = ["dep:oxc_allocator", "dep:oxc_parser", "dep:oxc_span", "dep:oxc_t
|
|||
semantic = ["dep:oxc_allocator", "dep:oxc_parser", "dep:oxc_semantic", "dep:oxc_span", "dep:oxc_tasks_common"]
|
||||
minifier = [
|
||||
"dep:oxc_allocator",
|
||||
"dep:oxc_ast",
|
||||
"dep:oxc_minifier",
|
||||
"dep:oxc_parser",
|
||||
"dep:oxc_span",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use oxc_allocator::Allocator;
|
||||
use oxc_ast::AstBuilder;
|
||||
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use oxc_minifier::{CompressOptions, Minifier, MinifierOptions, RemoveSyntax};
|
||||
use oxc_minifier::{CompressOptions, Compressor};
|
||||
use oxc_parser::Parser;
|
||||
use oxc_span::SourceType;
|
||||
use oxc_tasks_common::TestFiles;
|
||||
|
|
@ -14,12 +13,12 @@ fn bench_minifier(criterion: &mut Criterion) {
|
|||
BenchmarkId::from_parameter(&file.file_name),
|
||||
&file.source_text,
|
||||
|b, source_text| {
|
||||
let options = MinifierOptions::default();
|
||||
let options = CompressOptions::all_true();
|
||||
b.iter_with_large_drop(|| {
|
||||
let allocator = Allocator::default();
|
||||
let program = Parser::new(&allocator, source_text, source_type).parse().program;
|
||||
let program = allocator.alloc(program);
|
||||
Minifier::new(options).build(&allocator, program);
|
||||
Compressor::new(&allocator, options).build(program);
|
||||
allocator
|
||||
});
|
||||
},
|
||||
|
|
@ -28,28 +27,5 @@ fn bench_minifier(criterion: &mut Criterion) {
|
|||
group.finish();
|
||||
}
|
||||
|
||||
fn bench_passes(criterion: &mut Criterion) {
|
||||
let mut group = criterion.benchmark_group("prepass");
|
||||
|
||||
for file in TestFiles::minimal().files() {
|
||||
let source_type = SourceType::from_path(&file.file_name).unwrap();
|
||||
group.bench_with_input(
|
||||
BenchmarkId::from_parameter(&file.file_name),
|
||||
&file.source_text,
|
||||
|b, source_text| {
|
||||
let allocator = Allocator::default();
|
||||
let program = Parser::new(&allocator, source_text, source_type).parse().program;
|
||||
let program = allocator.alloc(program);
|
||||
b.iter(|| {
|
||||
RemoveSyntax::new(AstBuilder::new(&allocator), CompressOptions::all_true())
|
||||
.build(program);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(minifier, bench_minifier, bench_passes);
|
||||
criterion_group!(minifier, bench_minifier);
|
||||
criterion_main!(minifier);
|
||||
|
|
|
|||
Loading…
Reference in a new issue