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/metrics.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/metrics.rs')
-rw-r--r-- | runtime/metrics.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/runtime/metrics.rs b/runtime/metrics.rs index b42e0c551..a80ec5e21 100644 --- a/runtime/metrics.rs +++ b/runtime/metrics.rs @@ -101,27 +101,27 @@ impl OpMetrics { } } -use deno_core::BufVec; use deno_core::Op; use deno_core::OpFn; -use deno_core::OpState; -use std::cell::RefCell; use std::collections::HashMap; -use std::rc::Rc; pub fn metrics_op(name: &'static str, op_fn: Box<OpFn>) -> Box<OpFn> { - Box::new(move |op_state: Rc<RefCell<OpState>>, bufs: BufVec| -> Op { + Box::new(move |op_state, payload, buf| -> Op { // TODOs: // * The 'bytes' metrics seem pretty useless, especially now that the // distinction between 'control' and 'data' buffers has become blurry. // * Tracking completion of async ops currently makes us put the boxed // future into _another_ box. Keeping some counters may not be expensive // in itself, but adding a heap allocation for every metric seems bad. - let mut buf_len_iter = bufs.iter().map(|buf| buf.len()); - let bytes_sent_control = buf_len_iter.next().unwrap_or(0); - let bytes_sent_data = buf_len_iter.sum(); - let op = (op_fn)(op_state.clone(), bufs); + // TODO: remove this, doesn't make a ton of sense + let bytes_sent_control = 0; + let bytes_sent_data = match buf { + Some(ref b) => b.len(), + None => 0, + }; + + let op = (op_fn)(op_state.clone(), payload, buf); let op_state_ = op_state.clone(); let mut s = op_state.borrow_mut(); @@ -138,17 +138,17 @@ pub fn metrics_op(name: &'static str, op_fn: Box<OpFn>) -> Box<OpFn> { match op { Op::Sync(buf) => { - metrics.op_sync(bytes_sent_control, bytes_sent_data, buf.len()); + metrics.op_sync(bytes_sent_control, bytes_sent_data, 0); Op::Sync(buf) } Op::Async(fut) => { metrics.op_dispatched_async(bytes_sent_control, bytes_sent_data); let fut = fut - .inspect(move |buf| { + .inspect(move |_resp| { let mut s = op_state_.borrow_mut(); let runtime_metrics = s.borrow_mut::<RuntimeMetrics>(); let metrics = runtime_metrics.ops.get_mut(name).unwrap(); - metrics.op_completed_async(buf.len()); + metrics.op_completed_async(0); }) .boxed_local(); Op::Async(fut) @@ -156,11 +156,11 @@ pub fn metrics_op(name: &'static str, op_fn: Box<OpFn>) -> Box<OpFn> { Op::AsyncUnref(fut) => { metrics.op_dispatched_async_unref(bytes_sent_control, bytes_sent_data); let fut = fut - .inspect(move |buf| { + .inspect(move |_resp| { let mut s = op_state_.borrow_mut(); let runtime_metrics = s.borrow_mut::<RuntimeMetrics>(); let metrics = runtime_metrics.ops.get_mut(name).unwrap(); - metrics.op_completed_async_unref(buf.len()); + metrics.op_completed_async_unref(0); }) .boxed_local(); Op::AsyncUnref(fut) |