mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
perf: lazily retrieve ppid (#18940)
This is very apparent on Windows. Before: 45.74ms (Hello world) After: 33.92ms Closes #18939
This commit is contained in:
parent
dcf391ffed
commit
30628288ce
4 changed files with 29 additions and 28 deletions
|
@ -26,7 +26,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
|
||||||
"listen",
|
"listen",
|
||||||
"listenDatagram",
|
"listenDatagram",
|
||||||
"dlopen",
|
"dlopen",
|
||||||
"ppid",
|
|
||||||
"removeSignalListener",
|
"removeSignalListener",
|
||||||
"shutdown",
|
"shutdown",
|
||||||
"umask",
|
"umask",
|
||||||
|
|
|
@ -427,12 +427,11 @@ function bootstrapMainRuntime(runtimeOptions) {
|
||||||
8: tsVersion,
|
8: tsVersion,
|
||||||
9: unstableFlag,
|
9: unstableFlag,
|
||||||
10: pid,
|
10: pid,
|
||||||
11: ppid,
|
11: target,
|
||||||
12: target,
|
12: v8Version,
|
||||||
13: v8Version,
|
13: userAgent,
|
||||||
14: userAgent,
|
14: inspectFlag,
|
||||||
15: inspectFlag,
|
// 15: enableTestingFeaturesFlag
|
||||||
// 16: enableTestingFeaturesFlag
|
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
performance.setTimeOrigin(DateNow());
|
performance.setTimeOrigin(DateNow());
|
||||||
|
@ -495,9 +494,16 @@ function bootstrapMainRuntime(runtimeOptions) {
|
||||||
setUserAgent(userAgent);
|
setUserAgent(userAgent);
|
||||||
setLanguage(locale);
|
setLanguage(locale);
|
||||||
|
|
||||||
|
let ppid = undefined;
|
||||||
ObjectDefineProperties(finalDenoNs, {
|
ObjectDefineProperties(finalDenoNs, {
|
||||||
pid: util.readOnly(pid),
|
pid: util.readOnly(pid),
|
||||||
ppid: util.readOnly(ppid),
|
ppid: util.getterOnly(() => {
|
||||||
|
// lazy because it's expensive
|
||||||
|
if (ppid === undefined) {
|
||||||
|
ppid = ops.op_ppid();
|
||||||
|
}
|
||||||
|
return ppid;
|
||||||
|
}),
|
||||||
noColor: util.readOnly(noColor),
|
noColor: util.readOnly(noColor),
|
||||||
args: util.readOnly(ObjectFreeze(args)),
|
args: util.readOnly(ObjectFreeze(args)),
|
||||||
mainModule: util.getterOnly(opMainModule),
|
mainModule: util.getterOnly(opMainModule),
|
||||||
|
@ -535,12 +541,11 @@ function bootstrapWorkerRuntime(
|
||||||
8: tsVersion,
|
8: tsVersion,
|
||||||
9: unstableFlag,
|
9: unstableFlag,
|
||||||
10: pid,
|
10: pid,
|
||||||
// 11: ppid,
|
11: target,
|
||||||
12: target,
|
12: v8Version,
|
||||||
13: v8Version,
|
// 13: userAgent,
|
||||||
// 14: userAgent,
|
// 14: inspectFlag,
|
||||||
// 15: inspectFlag,
|
15: enableTestingFeaturesFlag,
|
||||||
16: enableTestingFeaturesFlag,
|
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
performance.setTimeOrigin(DateNow());
|
performance.setTimeOrigin(DateNow());
|
||||||
|
|
|
@ -8,7 +8,7 @@ use deno_core::OpState;
|
||||||
|
|
||||||
deno_core::extension!(
|
deno_core::extension!(
|
||||||
deno_runtime,
|
deno_runtime,
|
||||||
ops = [op_main_module],
|
ops = [op_main_module, op_ppid],
|
||||||
options = { main_module: ModuleSpecifier },
|
options = { main_module: ModuleSpecifier },
|
||||||
state = |state, options| {
|
state = |state, options| {
|
||||||
state.put::<ModuleSpecifier>(options.main_module);
|
state.put::<ModuleSpecifier>(options.main_module);
|
||||||
|
@ -31,7 +31,10 @@ fn op_main_module(state: &mut OpState) -> Result<String, AnyError> {
|
||||||
Ok(main_path)
|
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)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
// Adopted from rustup:
|
// Adopted from rustup:
|
||||||
|
|
|
@ -5,7 +5,6 @@ use deno_core::ModuleSpecifier;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::ops::runtime::ppid;
|
|
||||||
|
|
||||||
/// Common bootstrap options for MainWorker & WebWorker
|
/// Common bootstrap options for MainWorker & WebWorker
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -61,7 +60,7 @@ impl BootstrapOptions {
|
||||||
&self,
|
&self,
|
||||||
scope: &mut v8::HandleScope<'s>,
|
scope: &mut v8::HandleScope<'s>,
|
||||||
) -> v8::Local<'s, v8::Array> {
|
) -> v8::Local<'s, v8::Array> {
|
||||||
let array = v8::Array::new(scope, 17);
|
let array = v8::Array::new(scope, 16);
|
||||||
|
|
||||||
{
|
{
|
||||||
let args = v8::Array::new(scope, self.args.len() as i32);
|
let args = v8::Array::new(scope, self.args.len() as i32);
|
||||||
|
@ -142,18 +141,13 @@ impl BootstrapOptions {
|
||||||
array.set_index(scope, 10, val.into());
|
array.set_index(scope, 10, val.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
let val = v8::Integer::new(scope, ppid() as i32);
|
|
||||||
array.set_index(scope, 11, val.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let val = v8::String::new_external_onebyte_static(
|
let val = v8::String::new_external_onebyte_static(
|
||||||
scope,
|
scope,
|
||||||
env!("TARGET").as_bytes(),
|
env!("TARGET").as_bytes(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
array.set_index(scope, 12, val.into());
|
array.set_index(scope, 11, val.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -163,7 +157,7 @@ impl BootstrapOptions {
|
||||||
v8::NewStringType::Normal,
|
v8::NewStringType::Normal,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
array.set_index(scope, 13, val.into());
|
array.set_index(scope, 12, val.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -173,17 +167,17 @@ impl BootstrapOptions {
|
||||||
v8::NewStringType::Normal,
|
v8::NewStringType::Normal,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
array.set_index(scope, 14, val.into());
|
array.set_index(scope, 13, val.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let val = v8::Boolean::new(scope, self.inspect);
|
let val = v8::Boolean::new(scope, self.inspect);
|
||||||
array.set_index(scope, 15, val.into());
|
array.set_index(scope, 14, val.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let val = v8::Boolean::new(scope, self.enable_testing_features);
|
let val = v8::Boolean::new(scope, self.enable_testing_features);
|
||||||
array.set_index(scope, 16, val.into());
|
array.set_index(scope, 15, val.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
array
|
array
|
||||||
|
|
Loading…
Reference in a new issue