diff options
| author | Matt Mastracci <matthew@mastracci.com> | 2023-04-30 10:50:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-30 08:50:24 +0000 |
| commit | bb1f5e4262940a966e6314f57a4267514911d262 (patch) | |
| tree | 0b5b870e34fca10daf8e664eb4214e5e756daf53 /ops/lib.rs | |
| parent | 9c8ebce3dcc784f1a6ecd29d5fe0b3d35256ab82 (diff) | |
perf(core): async op pseudo-codegen and performance work (#18887)
Performance:
```
async_ops.js: 760k -> 1030k (!)
async_ops_deferred.js: 730k -> 770k
Deno.serve bench: 118k -> 124k
WS test w/ third_party/prebuilt/mac/load_test 100 localhost 8000 0 0: unchanged
Startup time: approx 0.5ms slower (13.7 -> 14.2ms)
```
Diffstat (limited to 'ops/lib.rs')
| -rw-r--r-- | ops/lib.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/ops/lib.rs b/ops/lib.rs index 5a192537f..d4fa0bb82 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -144,6 +144,8 @@ impl Op { is_unstable: #is_unstable, is_v8: #is_v8, force_registration: false, + // TODO(mmastrac) + arg_count: 0, } } @@ -158,8 +160,8 @@ impl Op { let has_fallible_fast_call = active && optimizer.returns_result; - let v8_body = if is_async { - let deferred = attrs.deferred; + let (v8_body, arg_count) = if is_async { + let deferred: bool = attrs.deferred; codegen_v8_async( &core, &item, @@ -205,6 +207,7 @@ impl Op { is_unstable: #is_unstable, is_v8: #is_v8, force_registration: false, + arg_count: #arg_count as u8, } } @@ -241,7 +244,7 @@ fn codegen_v8_async( margs: Attributes, asyncness: bool, deferred: bool, -) -> TokenStream2 { +) -> (TokenStream2, usize) { let Attributes { is_v8, .. } = margs; let special_args = f .sig @@ -309,7 +312,7 @@ fn codegen_v8_async( } }; - quote! { + let token_stream = quote! { use #core::futures::FutureExt; // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime let ctx = unsafe { @@ -336,7 +339,10 @@ fn codegen_v8_async( if let Some(response) = maybe_response { rv.set(response); } - } + }; + + // +1 arg for the promise ID + (token_stream, 1 + f.sig.inputs.len() - rust_i0) } fn scope_arg(arg: &FnArg) -> Option<TokenStream2> { @@ -373,7 +379,7 @@ fn codegen_v8_sync( f: &syn::ItemFn, margs: Attributes, has_fallible_fast_call: bool, -) -> TokenStream2 { +) -> (TokenStream2, usize) { let Attributes { is_v8, .. } = margs; let special_args = f .sig @@ -404,7 +410,7 @@ fn codegen_v8_sync( quote! {} }; - quote! { + let token_stream = quote! { // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime let ctx = unsafe { &*(#core::v8::Local::<#core::v8::External>::cast(args.data()).value() @@ -421,7 +427,9 @@ fn codegen_v8_sync( op_state.tracker.track_sync(ctx.id); #ret - } + }; + + (token_stream, f.sig.inputs.len() - rust_i0) } /// (full declarations, idents, v8 argument count) |
