diff options
| author | Matt Mastracci <matthew@mastracci.com> | 2023-06-25 16:36:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-25 16:36:09 +0200 |
| commit | 8fe9b8a4cc381f9b94ce2caf10c61ddff864bdb4 (patch) | |
| tree | 9ae0797ef865f0f0a023052f7dbe433d238561d4 /ops/op2/test_cases/sync/result_void.out | |
| parent | 3fe44a50c37b3f045c95a2085b58cfe3f71e8f6a (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/test_cases/sync/result_void.out')
| -rw-r--r-- | ops/op2/test_cases/sync/result_void.out | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/ops/op2/test_cases/sync/result_void.out b/ops/op2/test_cases/sync/result_void.out index 74c0c66a6..afc10582b 100644 --- a/ops/op2/test_cases/sync/result_void.out +++ b/ops/op2/test_cases/sync/result_void.out @@ -9,7 +9,15 @@ impl op_void_with_result { name: stringify!(op_void_with_result), v8_fn_ptr: Self::slow_function as _, enabled: true, - fast_fn: None, + fast_fn: Some({ + use deno_core::v8::fast_api::Type; + use deno_core::v8::fast_api::CType; + deno_core::v8::fast_api::FastFunction::new( + &[Type::V8Value, Type::CallbackOptions], + CType::Void, + Self::fast_function as *const ::std::ffi::c_void, + ) + }), is_async: false, is_unstable: false, is_v8: false, @@ -17,6 +25,27 @@ impl op_void_with_result { } } pub extern "C" fn slow_function(info: *const deno_core::v8::FunctionCallbackInfo) { + let args = deno_core::v8::FunctionCallbackArguments::from_function_callback_info(unsafe { + &*info + }); + let opctx = unsafe { + &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value() + as *const deno_core::_ops::OpCtx) + }; + if let Some(err) = unsafe { opctx.unsafely_take_last_error_for_ops_only() } { + let scope = &mut unsafe { deno_core::v8::CallbackScope::new(&*info) }; + let args = deno_core::v8::FunctionCallbackArguments::from_function_callback_info(unsafe { + &*info + }); + let opstate = ::std::cell::RefCell::borrow(&*opctx.state); + let exception = deno_core::error::to_v8_error( + scope, + opstate.get_error_class_fn, + &err, + ); + scope.throw_exception(exception); + return; + } let result = Self::call(); match result { Ok(result) => {} @@ -25,10 +54,6 @@ impl op_void_with_result { let args = deno_core::v8::FunctionCallbackArguments::from_function_callback_info(unsafe { &*info }); - let opctx = unsafe { - &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()) - .value() as *const deno_core::_ops::OpCtx) - }; let opstate = ::std::cell::RefCell::borrow(&*opctx.state); let exception = deno_core::error::to_v8_error( scope, @@ -40,6 +65,30 @@ impl op_void_with_result { } }; } + fn fast_function( + _: deno_core::v8::Local<deno_core::v8::Object>, + fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, + ) -> () { + let fast_api_callback_options = unsafe { &mut *fast_api_callback_options }; + let opctx = unsafe { + &*(deno_core::v8::Local::< + v8::External, + >::cast(unsafe { fast_api_callback_options.data.data }) + .value() as *const deno_core::_ops::OpCtx) + }; + let result = Self::call(); + let result = match result { + Ok(result) => result, + Err(err) => { + unsafe { + opctx.unsafely_set_last_error_for_ops_only(err); + } + fast_api_callback_options.fallback = true; + return ::std::default::Default::default(); + } + }; + result + } #[inline(always)] pub fn call() -> Result<(), AnyError> {} } |
