From 3487fde236d0852a8b0672c293fa41a741f471e8 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Fri, 17 Mar 2023 16:15:27 -0600 Subject: perf(core) Reduce copying and cloning in extension initialization (#18252) Follow-up to #18210: * we are passing the generated `cfg` object into the state function rather than passing individual config fields * reduce cloning dramatically by making the state_fn `FnOnce` * `take` for `ExtensionBuilder` to avoid more unnecessary copies * renamed `config` to `options` --- runtime/ops/os/mod.rs | 6 +++--- runtime/ops/runtime.rs | 6 +++--- runtime/ops/worker_host.rs | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'runtime/ops') diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 87181654b..b34629395 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -42,11 +42,11 @@ deno_core::ops!( deno_core::extension!( deno_os, ops_fn = deno_ops, - config = { + options = { exit_code: ExitCode, }, - state = |state, exit_code| { - state.put::(exit_code); + state = |state, options| { + state.put::(options.exit_code); }, ); diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 564d2279b..a77e888c8 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -9,9 +9,9 @@ use deno_core::OpState; deno_core::extension!( deno_runtime, ops = [op_main_module], - config = { main_module: ModuleSpecifier }, - state = |state, main_module| { - state.put::(main_module); + options = { main_module: ModuleSpecifier }, + state = |state, options| { + state.put::(options.main_module); } ); diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index de7e02e18..26c99efab 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -96,27 +96,27 @@ deno_core::extension!( op_host_recv_ctrl, op_host_recv_message, ], - config = { + options = { create_web_worker_cb: Arc, preload_module_cb: Arc, pre_execute_module_cb: Arc, format_js_error_fn: Option>, }, - state = |state, create_web_worker_cb, preload_module_cb, pre_execute_module_cb, format_js_error_fn| { + state = |state, options| { state.put::(WorkersTable::default()); state.put::(WorkerId::default()); let create_web_worker_cb_holder = - CreateWebWorkerCbHolder(create_web_worker_cb.clone()); + CreateWebWorkerCbHolder(options.create_web_worker_cb); state.put::(create_web_worker_cb_holder); let preload_module_cb_holder = - PreloadModuleCbHolder(preload_module_cb.clone()); + PreloadModuleCbHolder(options.preload_module_cb); state.put::(preload_module_cb_holder); let pre_execute_module_cb_holder = - PreExecuteModuleCbHolder(pre_execute_module_cb.clone()); + PreExecuteModuleCbHolder(options.pre_execute_module_cb); state.put::(pre_execute_module_cb_holder); let format_js_error_fn_holder = - FormatJsErrorFnHolder(format_js_error_fn.clone()); + FormatJsErrorFnHolder(options.format_js_error_fn); state.put::(format_js_error_fn_holder); } ); -- cgit v1.2.3