diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 4aca9ccf18ba4..be192b7f1a510 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -25,6 +25,8 @@ jobs: steps: - name: Checkout Branch uses: actions/checkout@v4 + with: + submodules: true # Pull submodules for additional files - name: Install Rust Toolchain uses: ./.github/actions/rustup diff --git a/Cargo.lock b/Cargo.lock index 0785cedf3dd7e..e91a35730a5bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1458,6 +1458,7 @@ dependencies = [ "oxc_semantic", "oxc_span", "oxc_tasks_common", + "oxc_transformer", "rayon", ] diff --git a/Cargo.toml b/Cargo.toml index cee9324ea5475..869c36197fdcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ oxc_type_synthesis = { path = "crates/oxc_type_synthesis" } oxc_resolver = { path = "crates/oxc_resolver" } oxc_query = { path = "crates/oxc_query" } oxc_linter_plugin = { path = "crates/oxc_linter_plugin" } +oxc_transformer = { path = "crates/oxc_transformer" } oxc_tasks_common = { path = "tasks/common" } oxc_vscode = { path = "editor/vscode/server" } diff --git a/tasks/benchmark/Cargo.toml b/tasks/benchmark/Cargo.toml index d9c62103fb91d..41495bf1f441d 100644 --- a/tasks/benchmark/Cargo.toml +++ b/tasks/benchmark/Cargo.toml @@ -17,6 +17,10 @@ bench = false name = "parser" harness = false +[[bench]] +name = "transformer" +harness = false + [[bench]] name = "semantic" harness = false @@ -42,6 +46,7 @@ oxc_tasks_common = { workspace = true } oxc_semantic = { workspace = true } oxc_resolver = { workspace = true } oxc_linter = { workspace = true } +oxc_transformer = { workspace = true } rayon = { workspace = true } criterion = { workspace = true } codspeed-criterion-compat = { workspace = true, optional = true } diff --git a/tasks/benchmark/benches/transformer.rs b/tasks/benchmark/benches/transformer.rs new file mode 100644 index 0000000000000..4473df86c7be5 --- /dev/null +++ b/tasks/benchmark/benches/transformer.rs @@ -0,0 +1,44 @@ +#[cfg(not(target_env = "msvc"))] +#[global_allocator] +static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; + +#[cfg(target_os = "windows")] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + +use std::{fs, hint::black_box}; + +use oxc_allocator::Allocator; +use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use oxc_parser::Parser; +use oxc_span::SourceType; +use oxc_tasks_common::project_root; +use oxc_transformer::{TransformOptions, Transformer}; + +fn bench_transformer(criterion: &mut Criterion) { + let mut group = criterion.benchmark_group("transformer"); + + let dir = project_root().join("tasks/coverage/typescript/src/compiler"); + let files = ["binder.ts", "scanner.ts", "checker.ts", "parser.ts"]; + + for file in files { + let path = dir.join(file); + let source_text = fs::read_to_string(&path).unwrap(); + let source_type = SourceType::from_path(file).unwrap(); + let id = BenchmarkId::from_parameter(file); + group.bench_with_input(id, &source_text, |b, source_text| { + let allocator = Allocator::default(); + let ret = Parser::new(&allocator, source_text, source_type).parse(); + let program = allocator.alloc(ret.program); + let transform_options = TransformOptions::default(); + b.iter(|| { + Transformer::new(&allocator, &transform_options).build(black_box(program)); + }); + }); + } + + group.finish(); +} + +criterion_group!(transformer, bench_transformer); +criterion_main!(transformer);