diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-03-21 16:33:12 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 22:33:12 +0000 |
commit | 0b4770fa7daf274ab01923fb09fd604aeb27e417 (patch) | |
tree | bee10a226239c2787caa87944a5f80783048d9f9 /bench_util/js_runtime.rs | |
parent | 253b556e6f430012c3094d47838fe397fa588028 (diff) |
perf(core) Reduce script name and script code copies (#18298)
Reduce the number of copies and allocations of script code by carrying
around ownership/reference information from creation time.
As an advantage, this allows us to maintain the identity of `&'static
str`-based scripts and use v8's external 1-byte strings (to avoid
incorrectly passing non-ASCII strings, debug `assert!`s gate all string
reference paths).
Benchmark results:
Perf improvements -- ~0.1 - 0.2ms faster, but should reduce garbage
w/external strings and reduces data copies overall. May also unlock some
more interesting optimizations in the future.
This requires adding some generics to functions, but manual
monomorphization has been applied (outer/inner function) to avoid code
bloat.
Diffstat (limited to 'bench_util/js_runtime.rs')
-rw-r--r-- | bench_util/js_runtime.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/bench_util/js_runtime.rs b/bench_util/js_runtime.rs index e381ba16b..4a5123a73 100644 --- a/bench_util/js_runtime.rs +++ b/bench_util/js_runtime.rs @@ -103,7 +103,8 @@ pub fn bench_js_async_with( opts.benching_inner }; let looped = loop_code(inner_iters, src); - let src = looped.as_ref(); + // Get a &'static str by leaking -- this is fine because it's benchmarking code + let src = Box::leak(looped.into_boxed_str()); if is_profiling() { for _ in 0..opts.profiling_outer { tokio_runtime.block_on(inner_async(src, &mut runtime)); @@ -115,7 +116,7 @@ pub fn bench_js_async_with( } } -async fn inner_async(src: &str, runtime: &mut JsRuntime) { +async fn inner_async(src: &'static str, runtime: &mut JsRuntime) { runtime.execute_script("inner_loop", src).unwrap(); runtime.run_event_loop(false).await.unwrap(); } |