Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(benchmarks): exclude parser from isolated declarations benchmark timing #9388

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions tasks/benchmark/benches/isolated_declarations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_allocator::Allocator;
use oxc_benchmark::{BenchmarkId, Criterion, criterion_group, criterion_main};
use oxc_benchmark::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
use oxc_isolated_declarations::{IsolatedDeclarations, IsolatedDeclarationsOptions};
use oxc_parser::{Parser, ParserReturn};
use oxc_parser::Parser;
use oxc_span::SourceType;
use oxc_tasks_common::TestFile;

Expand All @@ -16,16 +16,25 @@ fn bench_isolated_declarations(criterion: &mut Criterion) {
let source_text = file.source_text.as_str();
let source_type = SourceType::from_path(&file.file_name).unwrap();

let ast_allocator = Allocator::new();
let program = Parser::new(&ast_allocator, source_text, source_type).parse().program;
let program = black_box(program);

// Create `Allocator` outside of `bench_function`, so same allocator is used for
// both the warmup and measurement phases
let mut output_allocator = Allocator::new();
group.bench_function(id, |b| {
b.iter_with_large_drop(|| {
let allocator = Allocator::default();
let ParserReturn { program, .. } =
Parser::new(&allocator, source_text, source_type).parse();
IsolatedDeclarations::new(
&allocator,
IsolatedDeclarationsOptions { strip_internal: true },
)
.build(&program);
b.iter_with_setup_wrapper(|runner| {
// Reset allocator at start of each iteration
output_allocator.reset();

// Include dropping `IsolatedDeclarations::build`'s return value in benchmark timing.
// Drop time is part of the cost of using this API.
runner.run(|| {
let options = IsolatedDeclarationsOptions { strip_internal: true };
let ret = IsolatedDeclarations::new(&output_allocator, options).build(&program);
black_box(ret);
});
});
});

Expand Down
Loading