Skip to content

Commit

Permalink
Make optimization opt-out and disable them in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Mar 21, 2023
1 parent 8c26701 commit 3617c8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion boa_engine/benches/full.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Benchmarks of the whole execution engine in Boa.
use boa_engine::{context::DefaultHooks, realm::Realm, Context, Source};
use boa_engine::{
context::DefaultHooks, optimizer::OptimizerOptions, realm::Realm, Context, Source,
};
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

Expand All @@ -24,6 +26,10 @@ macro_rules! full_benchmarks {
{
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
let mut context = Context::default();

// Disable optimizations
context.set_optimizer_options(OptimizerOptions::empty());

c.bench_function(concat!($id, " (Parser)"), move |b| {
b.iter(|| context.parse_script(black_box(Source::from_bytes(CODE))))
});
Expand All @@ -35,6 +41,10 @@ macro_rules! full_benchmarks {
{
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
let mut context = Context::default();

// Disable optimizations
context.set_optimizer_options(OptimizerOptions::empty());

let statement_list = context.parse_script(Source::from_bytes(CODE)).expect("parsing failed");
c.bench_function(concat!($id, " (Compiler)"), move |b| {
b.iter(|| {
Expand All @@ -49,6 +59,10 @@ macro_rules! full_benchmarks {
{
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
let mut context = Context::default();

// Disable optimizations
context.set_optimizer_options(OptimizerOptions::empty());

let statement_list = context.parse_script(Source::from_bytes(CODE)).expect("parsing failed");
let code_block = context.compile_script(&statement_list).unwrap();
c.bench_function(concat!($id, " (Execution)"), move |b| {
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl<'icu, 'hooks, 'queue> ContextBuilder<'icu, 'hooks, 'queue> {
kept_alive: Vec::new(),
host_hooks,
job_queue: self.job_queue.unwrap_or(&IdleJobQueue),
optimizer_options: OptimizerOptions::empty(),
optimizer_options: OptimizerOptions::OPTIMIZE_ALL,
};

builtins::set_default_global_bindings(&mut context)?;
Expand Down

0 comments on commit 3617c8d

Please sign in to comment.