1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 01:29:14 -05:00
denoland-deno/runtime/worker_bootstrap.rs
Bartek Iwańczuk 4c6db7aa14
perf(core, runtime): Further improve startup time (#17860)
This commit further improves startup time by:

- no relying on "JsRuntime::execute_script" for runtime bootstrapping,
this is instead done using V8 APIs directly
- registering error classes during the snapshot time, instead of on
startup

Further improvements can be made, mainly around removing 
"core.initializeAsyncOps()" which takes around 2ms.

This commit should result in ~1ms startup time improvement.
2023-02-22 06:25:31 +05:30

85 lines
2.3 KiB
Rust

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::ModuleSpecifier;
use std::thread;
use crate::colors;
use crate::ops::runtime::ppid;
/// Common bootstrap options for MainWorker & WebWorker
#[derive(Clone)]
pub struct BootstrapOptions {
/// Sets `Deno.args` in JS runtime.
pub args: Vec<String>,
pub cpu_count: usize,
pub debug_flag: bool,
pub enable_testing_features: bool,
pub locale: String,
pub location: Option<ModuleSpecifier>,
/// Sets `Deno.noColor` in JS runtime.
pub no_color: bool,
pub is_tty: bool,
/// Sets `Deno.version.deno` in JS runtime.
pub runtime_version: String,
/// Sets `Deno.version.typescript` in JS runtime.
pub ts_version: String,
pub unstable: bool,
pub user_agent: String,
pub inspect: bool,
}
impl Default for BootstrapOptions {
fn default() -> Self {
let cpu_count = thread::available_parallelism()
.map(|p| p.get())
.unwrap_or(1);
let runtime_version = env!("CARGO_PKG_VERSION").into();
let user_agent = format!("Deno/{runtime_version}");
Self {
runtime_version,
user_agent,
cpu_count,
no_color: !colors::use_color(),
is_tty: colors::is_tty(),
enable_testing_features: Default::default(),
debug_flag: Default::default(),
ts_version: Default::default(),
locale: "en".to_string(),
location: Default::default(),
unstable: Default::default(),
inspect: Default::default(),
args: Default::default(),
}
}
}
impl BootstrapOptions {
pub fn as_json(&self) -> serde_json::Value {
json!({
// Shared bootstrap args
"args": self.args,
"cpuCount": self.cpu_count,
"debugFlag": self.debug_flag,
"denoVersion": self.runtime_version,
"locale": self.locale,
"location": self.location,
"noColor": self.no_color,
"isTty": self.is_tty,
"tsVersion": self.ts_version,
"unstableFlag": self.unstable,
// Web worker only
"enableTestingFeaturesFlag": self.enable_testing_features,
// Env values
"pid": std::process::id(),
"ppid": ppid(),
"target": env!("TARGET"),
"v8Version": deno_core::v8_version(),
"userAgent": self.user_agent,
"inspectFlag": self.inspect,
})
}
}