diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-11-26 20:48:17 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 04:48:17 +0000 |
commit | 9ffc6acdbb3326dde74c803332547b0ae33e483a (patch) | |
tree | e3d45392c1f6d41fac66f59c2f216f81b9a86c6e /ops/fast_call.rs | |
parent | 0012484f4f194664bea87879ab9f4f20f4ee86c6 (diff) |
perf(ops): Reenable fast unit result optimization (#16827)
The optimization was missed in the optimizer rewrite
https://github.com/denoland/deno/pull/16514
Diffstat (limited to 'ops/fast_call.rs')
-rw-r--r-- | ops/fast_call.rs | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/ops/fast_call.rs b/ops/fast_call.rs index 8f6348ec4..07bf87026 100644 --- a/ops/fast_call.rs +++ b/ops/fast_call.rs @@ -141,10 +141,19 @@ pub(crate) fn generate( if optimizer.has_fast_callback_option || optimizer.needs_opstate() || optimizer.is_async + || optimizer.needs_fast_callback_option { - fast_fn_inputs.push(parse_quote! { + let decl = parse_quote! { fast_api_callback_options: *mut #core::v8::fast_api::FastApiCallbackOptions - }); + }; + + if optimizer.has_fast_callback_option { + // Replace last parameter. + assert!(fast_fn_inputs.pop().is_some()); + fast_fn_inputs.push(decl); + } else { + fast_fn_inputs.push(decl); + } input_variants.push(q!({ CallbackOptions })); } @@ -162,14 +171,10 @@ pub(crate) fn generate( let mut output_transforms = q!({}); - if optimizer.needs_opstate() || optimizer.is_async { - // Grab the op_state identifier, the first one. ¯\_(ツ)_/¯ - let op_state = match idents.first() { - Some(ident) if optimizer.has_opstate_in_parameters() => ident.clone(), - // fn op_foo() -> Result<...> - _ => Ident::new("op_state", Span::call_site()), - }; - + if optimizer.needs_opstate() + || optimizer.is_async + || optimizer.has_fast_callback_option + { // Dark arts 🪄 ✨ // // - V8 calling convention guarantees that the callback options pointer is non-null. @@ -179,13 +184,27 @@ pub(crate) fn generate( let prelude = q!({ let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { &mut *fast_api_callback_options }; + }); + + pre_transforms.push_tokens(&prelude); + } + + if optimizer.needs_opstate() || optimizer.is_async { + // Grab the op_state identifier, the first one. ¯\_(ツ)_/¯ + let op_state = match idents.first() { + Some(ident) if optimizer.has_opstate_in_parameters() => ident.clone(), + // fn op_foo() -> Result<...> + _ => Ident::new("op_state", Span::call_site()), + }; + + let ctx = q!({ let __ctx = unsafe { &*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value() as *const _ops::OpCtx) }; }); - pre_transforms.push_tokens(&prelude); + pre_transforms.push_tokens(&ctx); pre_transforms.push_tokens(&match optimizer.is_async { false => q!( Vars { |