From fec1b2a5a4324a7eecdfbb2471931f3b6b0139c5 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Wed, 31 Mar 2021 16:37:38 +0200 Subject: 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 --- runtime/ops/plugin.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'runtime/ops/plugin.rs') 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>, - mut zero_copy: BufVec| { + let plugin_op_fn: Box = Box::new(move |state_rc, _payload, buf| { + // For sig compat map Option 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), ) } } -- cgit v1.2.3