summaryrefslogtreecommitdiff
path: root/ops/op2/mod.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-06-25 16:36:09 +0200
committerGitHub <noreply@github.com>2023-06-25 16:36:09 +0200
commit8fe9b8a4cc381f9b94ce2caf10c61ddff864bdb4 (patch)
tree9ae0797ef865f0f0a023052f7dbe433d238561d4 /ops/op2/mod.rs
parent3fe44a50c37b3f045c95a2085b58cfe3f71e8f6a (diff)
refactor(ops): ops2 supports result in fast path (#19603)
Implements `Result` in fast-calls. Note that the approach here is slightly different. Rather than store the last result in the `OpState`, we put it into the `OpCtx` which saves us a lookup and lock in the error case. We do not have to lock this field as it's guaranteed only one runtime and thread can ever access it. The fastcall path for many ops can avoid doing a great deal of work, even for `Result` return values. In the previous iteration of `ops`, all `Result`-returning functions would fetch and lock the `OpState`, regardless of whether it was used or not.
Diffstat (limited to 'ops/op2/mod.rs')
-rw-r--r--ops/op2/mod.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/ops/op2/mod.rs b/ops/op2/mod.rs
index 558d7c7dc..67a92d450 100644
--- a/ops/op2/mod.rs
+++ b/ops/op2/mod.rs
@@ -50,7 +50,7 @@ pub enum V8MappingError {
}
#[derive(Default)]
-struct MacroConfig {
+pub(crate) struct MacroConfig {
pub core: bool,
pub fast: bool,
}
@@ -135,6 +135,8 @@ fn generate_op2(
let opctx = Ident::new("opctx", Span::call_site());
let slow_function = Ident::new("slow_function", Span::call_site());
let fast_function = Ident::new("fast_function", Span::call_site());
+ let fast_api_callback_options =
+ Ident::new("fast_api_callback_options", Span::call_site());
let deno_core = if config.core {
syn2::parse_str::<Path>("crate")
@@ -151,6 +153,7 @@ fn generate_op2(
scope,
info,
opctx,
+ fast_api_callback_options,
deno_core,
result,
retval,
@@ -161,10 +164,14 @@ fn generate_op2(
needs_scope: false,
needs_opctx: false,
needs_opstate: false,
+ needs_fast_opctx: false,
+ needs_fast_api_callback_options: false,
};
let name = func.sig.ident;
- let slow_fn = generate_dispatch_slow(&mut generator_state, &signature)?;
+
+ let slow_fn =
+ generate_dispatch_slow(&config, &mut generator_state, &signature)?;
let (fast_definition, fast_fn) =
match generate_dispatch_fast(&mut generator_state, &signature)? {
Some((fast_definition, fast_fn)) => {