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 /cli/worker.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 'cli/worker.rs')
-rw-r--r-- | cli/worker.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/cli/worker.rs b/cli/worker.rs index c505516a0..a0168a1f3 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -78,7 +78,7 @@ impl CliMainWorker { self.execute_main_module_possibly_with_npm().await?; } - self.worker.dispatch_load_event(&located_script_name!())?; + self.worker.dispatch_load_event(located_script_name!())?; loop { self @@ -87,13 +87,13 @@ impl CliMainWorker { .await?; if !self .worker - .dispatch_beforeunload_event(&located_script_name!())? + .dispatch_beforeunload_event(located_script_name!())? { break; } } - self.worker.dispatch_unload_event(&located_script_name!())?; + self.worker.dispatch_unload_event(located_script_name!())?; if let Some(coverage_collector) = maybe_coverage_collector.as_mut() { self @@ -129,7 +129,7 @@ impl CliMainWorker { self .inner .worker - .dispatch_load_event(&located_script_name!())?; + .dispatch_load_event(located_script_name!())?; self.pending_unload = true; let result = loop { @@ -140,7 +140,7 @@ impl CliMainWorker { match self .inner .worker - .dispatch_beforeunload_event(&located_script_name!()) + .dispatch_beforeunload_event(located_script_name!()) { Ok(default_prevented) if default_prevented => {} // continue loop Ok(_) => break Ok(()), @@ -154,7 +154,7 @@ impl CliMainWorker { self .inner .worker - .dispatch_unload_event(&located_script_name!())?; + .dispatch_unload_event(located_script_name!())?; Ok(()) } @@ -166,7 +166,7 @@ impl CliMainWorker { let _ = self .inner .worker - .dispatch_unload_event(&located_script_name!()); + .dispatch_unload_event(located_script_name!()); } } } @@ -185,7 +185,7 @@ impl CliMainWorker { // failures. if self.ps.options.trace_ops() { self.worker.js_runtime.execute_script( - &located_script_name!(), + located_script_name!(), "Deno[Deno.internal].core.enableOpCallTracing();", )?; } @@ -200,19 +200,19 @@ impl CliMainWorker { self.execute_side_module_possibly_with_npm().await?; } - self.worker.dispatch_load_event(&located_script_name!())?; + self.worker.dispatch_load_event(located_script_name!())?; self.run_tests(&self.ps.options.shuffle_tests()).await?; loop { if !self .worker - .dispatch_beforeunload_event(&located_script_name!())? + .dispatch_beforeunload_event(located_script_name!())? { break; } self.worker.run_event_loop(false).await?; } - self.worker.dispatch_unload_event(&located_script_name!())?; + self.worker.dispatch_unload_event(located_script_name!())?; if let Some(coverage_collector) = maybe_coverage_collector.as_mut() { self @@ -230,7 +230,7 @@ impl CliMainWorker { self.enable_test(); self.worker.execute_script( - &located_script_name!(), + located_script_name!(), "Deno[Deno.internal].core.enableOpCallTracing();", )?; @@ -239,18 +239,18 @@ impl CliMainWorker { self.execute_side_module_possibly_with_npm().await?; } - self.worker.dispatch_load_event(&located_script_name!())?; + self.worker.dispatch_load_event(located_script_name!())?; self.run_tests(&None).await?; loop { if !self .worker - .dispatch_beforeunload_event(&located_script_name!())? + .dispatch_beforeunload_event(located_script_name!())? { break; } self.worker.run_event_loop(false).await?; } - self.worker.dispatch_unload_event(&located_script_name!())?; + self.worker.dispatch_unload_event(located_script_name!())?; Ok(()) } @@ -260,18 +260,18 @@ impl CliMainWorker { // We execute the module module as a side module so that import.meta.main is not set. self.execute_side_module_possibly_with_npm().await?; - self.worker.dispatch_load_event(&located_script_name!())?; + self.worker.dispatch_load_event(located_script_name!())?; self.run_benchmarks().await?; loop { if !self .worker - .dispatch_beforeunload_event(&located_script_name!())? + .dispatch_beforeunload_event(located_script_name!())? { break; } self.worker.run_event_loop(false).await?; } - self.worker.dispatch_unload_event(&located_script_name!())?; + self.worker.dispatch_unload_event(located_script_name!())?; Ok(()) } |