From 30628288ce2b411ca3def46129a4606073e16bac Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 1 May 2023 14:21:27 -0400 Subject: perf: lazily retrieve ppid (#18940) This is very apparent on Windows. Before: 45.74ms (Hello world) After: 33.92ms Closes #18939 --- runtime/ops/runtime.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'runtime/ops') diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 8802f9cd6..9f2e48d7a 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -8,7 +8,7 @@ use deno_core::OpState; deno_core::extension!( deno_runtime, - ops = [op_main_module], + ops = [op_main_module, op_ppid], options = { main_module: ModuleSpecifier }, state = |state, options| { state.put::(options.main_module); @@ -31,7 +31,10 @@ fn op_main_module(state: &mut OpState) -> Result { Ok(main_path) } -pub fn ppid() -> i64 { +/// This is an op instead of being done at initialization time because +/// it's expensive to retreive the ppid on Windows. +#[op] +pub fn op_ppid() -> i64 { #[cfg(windows)] { // Adopted from rustup: -- cgit v1.2.3