diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-03-31 16:37:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-31 10:37:38 -0400 |
commit | fec1b2a5a4324a7eecdfbb2471931f3b6b0139c5 (patch) | |
tree | 8a650553c2d70e047d9d7365f9ac8702ec9861a5 /runtime/ops/plugin.rs | |
parent | 6dc3549a818ad49b3907d18c93fd422a9cc743a5 (diff) |
refactor: new optimized op-layer using serde_v8 (#9843)
- Improves op performance.
- Handle op-metadata (errors, promise IDs) explicitly in the op-layer vs
per op-encoding (aka: out-of-payload).
- Remove shared queue & custom "asyncHandlers", all async values are
returned in batches via js_recv_cb.
- The op-layer should be thought of as simple function calls with little
indirection or translation besides the conceptually straightforward
serde_v8 bijections.
- Preserve concepts of json/bin/min as semantic groups of their
inputs/outputs instead of their op-encoding strategy, preserving these
groups will also facilitate partial transitions over to v8 Fast API for the
"min" and "bin" groups
Diffstat (limited to 'runtime/ops/plugin.rs')
-rw-r--r-- | runtime/ops/plugin.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/runtime/ops/plugin.rs b/runtime/ops/plugin.rs index 6952cf77f..7fc59d082 100644 --- a/runtime/ops/plugin.rs +++ b/runtime/ops/plugin.rs @@ -10,6 +10,7 @@ use deno_core::BufVec; use deno_core::JsRuntime; use deno_core::Op; use deno_core::OpAsyncFuture; +use deno_core::OpFn; use deno_core::OpId; use deno_core::OpState; use deno_core::Resource; @@ -18,7 +19,6 @@ use dlopen::symbor::Library; use log::debug; use serde::Deserialize; use std::borrow::Cow; -use std::cell::RefCell; use std::path::PathBuf; use std::pin::Pin; use std::rc::Rc; @@ -110,11 +110,17 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { dispatch_op_fn: plugin_api::DispatchOpFn, ) -> OpId { let plugin_lib = self.plugin_lib.clone(); - let plugin_op_fn = move |state_rc: Rc<RefCell<OpState>>, - mut zero_copy: BufVec| { + let plugin_op_fn: Box<OpFn> = Box::new(move |state_rc, _payload, buf| { + // For sig compat map Option<ZeroCopyBuf> to BufVec + let mut bufs: BufVec = match buf { + Some(b) => vec![b], + None => vec![], + } + .into(); + let mut state = state_rc.borrow_mut(); let mut interface = PluginInterface::new(&mut state, &plugin_lib); - let op = dispatch_op_fn(&mut interface, &mut zero_copy); + let op = dispatch_op_fn(&mut interface, &mut bufs); match op { sync_op @ Op::Sync(..) => sync_op, Op::Async(fut) => Op::Async(PluginOpAsyncFuture::new(&plugin_lib, fut)), @@ -123,13 +129,10 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { } _ => unreachable!(), } - }; + }); self.state.op_table.register_op( name, - metrics_op( - Box::leak(Box::new(name.to_string())), - Box::new(plugin_op_fn), - ), + metrics_op(Box::leak(Box::new(name.to_string())), plugin_op_fn), ) } } |