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

fix: make __callSiteEvals private #754

Merged
merged 1 commit into from
May 27, 2024

Conversation

0f-0b
Copy link
Contributor

@0f-0b 0f-0b commented May 23, 2024

No description provided.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. It seems reasonable - have you run any benchmarks? Is there any performance impact?

ref #739 (review)

@0f-0b
Copy link
Contributor Author

0f-0b commented May 26, 2024

Looks like it's faster with this change.

$ ./bench_main

running 1 test
test bench ... bench:   2,317,572 ns/iter (+/- 36,373)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured

$ ./bench_private_call_sites

running 1 test
test bench ... bench:   2,031,424 ns/iter (+/- 46,885)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured

Benchmark code:

use bencher::{benchmark_group, benchmark_main, Bencher};
use deno_core::{ascii_str, v8, JsRuntime, RuntimeOptions};

fn bench(b: &mut Bencher) {
  let mut runtime = JsRuntime::new(RuntimeOptions {
    unsafe_expose_natives_and_gc: true,
    ..Default::default()
  });
  runtime
    .execute_script(
      "",
      r#"
        function bench() {
          for (let i = 0; i < 1000; i++) {
            new Error().stack;
          }
        }

        %PrepareFunctionForOptimization(bench);
        bench();
        %OptimizeFunctionOnNextCall(bench);
        bench();
      "#,
    )
    .unwrap();
  let context = runtime.main_context();
  let scope = &mut runtime.handle_scope();
  let bench = {
    let key = ascii_str!("bench").v8_string(scope).into();
    let value = context.open(scope).global(scope).get(scope, key).unwrap();
    v8::Local::<v8::Function>::try_from(value).unwrap()
  };
  let recv = v8::undefined(scope).into();
  b.iter(|| bench.call(scope, recv, &[]));
}

benchmark_group!(benches, bench);
benchmark_main!(benches);

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, seems like a much better solution that doesn't expose this funky object.

@bartlomieju bartlomieju merged commit b2e84c0 into denoland:main May 27, 2024
18 checks passed
@0f-0b 0f-0b deleted the private-call-sites branch May 27, 2024 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants