From 4b6305f4f25fc76f974bbdcc9cdb139d5ab8f5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 18 Mar 2023 07:51:21 -0400 Subject: perf(core): preserve ops between snapshots (#18080) This commit changes the build process in a way that preserves already registered ops in the snapshot. This allows us to skip creating hundreds of "v8::String" on each startup, but sadly there is still some op registration going on startup (however we're registering 49 ops instead of >200 ops). This situation could be further improved, by moving some of the ops from "runtime/" to a separate extension crates. --------- Co-authored-by: Divy Srivastava --- runtime/ops/fs_events.rs | 5 ++++- runtime/ops/http.rs | 3 +++ runtime/ops/os/mod.rs | 14 +++++++------- runtime/ops/permissions.rs | 5 ++++- runtime/ops/process.rs | 5 ++++- runtime/ops/runtime.rs | 5 ++++- runtime/ops/signal.rs | 5 ++++- runtime/ops/tty.rs | 5 ++++- runtime/ops/web_worker.rs | 5 ++++- runtime/ops/worker_host.rs | 5 ++++- 10 files changed, 42 insertions(+), 15 deletions(-) (limited to 'runtime/ops') diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs index 05cc22152..27e76b3d3 100644 --- a/runtime/ops/fs_events.rs +++ b/runtime/ops/fs_events.rs @@ -30,7 +30,10 @@ use tokio::sync::mpsc; deno_core::extension!( deno_fs_events, - ops = [op_fs_events_open, op_fs_events_poll] + ops = [op_fs_events_open, op_fs_events_poll], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); struct FsEventsResource { diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index b9899b4e3..3a316d800 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -30,6 +30,9 @@ use tokio::net::UnixStream; deno_core::extension!( deno_http_runtime, ops = [op_http_start, op_http_upgrade, op_flash_upgrade_http], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); #[op] diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index b34629395..70a126301 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -48,23 +48,23 @@ deno_core::extension!( state = |state, options| { state.put::(options.exit_code); }, + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + } ); deno_core::extension!( deno_os_worker, ops_fn = deno_ops, middleware = |op| match op.name { - "op_exit" => noop_op::decl(), - "op_set_exit_code" => noop_op::decl(), + "op_exit" | "op_set_exit_code" => op.disable(), _ => op, }, + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + } ); -#[op] -fn noop_op() -> Result<(), AnyError> { - Ok(()) -} - #[op] fn op_exec_path(state: &mut OpState) -> Result { let current_exe = env::current_exe().unwrap(); diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index c08d11e4a..6f7b98a30 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -17,7 +17,10 @@ deno_core::extension!( op_query_permission, op_revoke_permission, op_request_permission, - ] + ], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); #[derive(Deserialize)] diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index a15b63f80..cf8740255 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -107,7 +107,10 @@ deno_core::extension!( deprecated::op_run, deprecated::op_run_status, deprecated::op_kill, - ] + ], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); struct ChildResource(tokio::process::Child); diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index a77e888c8..8802f9cd6 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -12,7 +12,10 @@ deno_core::extension!( options = { main_module: ModuleSpecifier }, state = |state, options| { state.put::(options.main_module); - } + }, + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); #[op] diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 9cc261d85..93e1cfef2 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -31,7 +31,10 @@ use tokio::signal::windows::CtrlC; deno_core::extension!( deno_signal, - ops = [op_signal_bind, op_signal_unbind, op_signal_poll] + ops = [op_signal_bind, op_signal_unbind, op_signal_poll], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); #[cfg(unix)] diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index 60144e408..3146f22e2 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -34,7 +34,10 @@ fn get_windows_handle( deno_core::extension!( deno_tty, - ops = [op_stdin_set_raw, op_isatty, op_console_size] + ops = [op_stdin_set_raw, op_isatty, op_console_size], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); // ref: diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index 45137913e..7952a03f2 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -24,7 +24,10 @@ deno_core::extension!( op_worker_close, op_worker_get_type, op_worker_sync_fetch, - ] + ], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); #[op] diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 26c99efab..d5285ec89 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -118,7 +118,10 @@ deno_core::extension!( let format_js_error_fn_holder = FormatJsErrorFnHolder(options.format_js_error_fn); state.put::(format_js_error_fn_holder); - } + }, + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.force_op_registration(); + }, ); #[derive(Deserialize)] -- cgit v1.2.3