mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
perf: static bootstrap options in snapshot (#21213)
Closes https://github.com/denoland/deno/issues/21133
This commit is contained in:
parent
c67de43ff3
commit
7f3902b41f
8 changed files with 66 additions and 47 deletions
18
cli/build.rs
18
cli/build.rs
|
@ -352,9 +352,18 @@ fn create_cli_snapshot(snapshot_path: PathBuf) -> CreateSnapshotOutput {
|
||||||
use deno_runtime::deno_cron::local::LocalCronHandler;
|
use deno_runtime::deno_cron::local::LocalCronHandler;
|
||||||
use deno_runtime::deno_http::DefaultHttpPropertyExtractor;
|
use deno_runtime::deno_http::DefaultHttpPropertyExtractor;
|
||||||
use deno_runtime::deno_kv::sqlite::SqliteDbHandler;
|
use deno_runtime::deno_kv::sqlite::SqliteDbHandler;
|
||||||
|
use deno_runtime::ops::bootstrap::SnapshotOptions;
|
||||||
use deno_runtime::permissions::PermissionsContainer;
|
use deno_runtime::permissions::PermissionsContainer;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
fn deno_version() -> String {
|
||||||
|
if env::var("DENO_CANARY").is_ok() {
|
||||||
|
format!("{}+{}", env!("CARGO_PKG_VERSION"), git_commit_hash())
|
||||||
|
} else {
|
||||||
|
env!("CARGO_PKG_VERSION").to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE(bartlomieju): ordering is important here, keep it in sync with
|
// NOTE(bartlomieju): ordering is important here, keep it in sync with
|
||||||
// `runtime/worker.rs`, `runtime/web_worker.rs` and `runtime/build.rs`!
|
// `runtime/worker.rs`, `runtime/web_worker.rs` and `runtime/build.rs`!
|
||||||
let fs = Arc::new(deno_fs::RealFs);
|
let fs = Arc::new(deno_fs::RealFs);
|
||||||
|
@ -405,7 +414,14 @@ fn create_cli_snapshot(snapshot_path: PathBuf) -> CreateSnapshotOutput {
|
||||||
deno_runtime::ops::signal::deno_signal::init_ops(),
|
deno_runtime::ops::signal::deno_signal::init_ops(),
|
||||||
deno_runtime::ops::tty::deno_tty::init_ops(),
|
deno_runtime::ops::tty::deno_tty::init_ops(),
|
||||||
deno_runtime::ops::http::deno_http_runtime::init_ops(),
|
deno_runtime::ops::http::deno_http_runtime::init_ops(),
|
||||||
deno_runtime::ops::bootstrap::deno_bootstrap::init_ops(),
|
deno_runtime::ops::bootstrap::deno_bootstrap::init_ops(Some(
|
||||||
|
SnapshotOptions {
|
||||||
|
deno_version: deno_version(),
|
||||||
|
ts_version: ts::version(),
|
||||||
|
v8_version: deno_core::v8_version(),
|
||||||
|
target: std::env::var("TARGET").unwrap(),
|
||||||
|
},
|
||||||
|
)),
|
||||||
cli::init_ops_and_esm(), // NOTE: This needs to be init_ops_and_esm!
|
cli::init_ops_and_esm(), // NOTE: This needs to be init_ops_and_esm!
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -559,8 +559,6 @@ impl CliMainWorkerFactory {
|
||||||
location: shared.options.location.clone(),
|
location: shared.options.location.clone(),
|
||||||
no_color: !colors::use_color(),
|
no_color: !colors::use_color(),
|
||||||
is_tty: colors::is_tty(),
|
is_tty: colors::is_tty(),
|
||||||
runtime_version: version::deno().to_string(),
|
|
||||||
ts_version: version::TYPESCRIPT.to_string(),
|
|
||||||
unstable: shared.options.unstable,
|
unstable: shared.options.unstable,
|
||||||
unstable_features,
|
unstable_features,
|
||||||
user_agent: version::get_user_agent().to_string(),
|
user_agent: version::get_user_agent().to_string(),
|
||||||
|
@ -755,8 +753,6 @@ fn create_web_worker_callback(
|
||||||
location: Some(args.main_module.clone()),
|
location: Some(args.main_module.clone()),
|
||||||
no_color: !colors::use_color(),
|
no_color: !colors::use_color(),
|
||||||
is_tty: colors::is_tty(),
|
is_tty: colors::is_tty(),
|
||||||
runtime_version: version::deno().to_string(),
|
|
||||||
ts_version: version::TYPESCRIPT.to_string(),
|
|
||||||
unstable: shared.options.unstable,
|
unstable: shared.options.unstable,
|
||||||
unstable_features,
|
unstable_features,
|
||||||
user_agent: version::get_user_agent().to_string(),
|
user_agent: version::get_user_agent().to_string(),
|
||||||
|
|
|
@ -450,6 +450,13 @@ const finalDenoNs = {
|
||||||
...denoNs,
|
...denoNs,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const {
|
||||||
|
denoVersion,
|
||||||
|
tsVersion,
|
||||||
|
v8Version,
|
||||||
|
target,
|
||||||
|
} = ops.op_snapshot_options();
|
||||||
|
|
||||||
function bootstrapMainRuntime(runtimeOptions) {
|
function bootstrapMainRuntime(runtimeOptions) {
|
||||||
if (hasBootstrapped) {
|
if (hasBootstrapped) {
|
||||||
throw new Error("Worker runtime already bootstrapped");
|
throw new Error("Worker runtime already bootstrapped");
|
||||||
|
@ -457,16 +464,12 @@ function bootstrapMainRuntime(runtimeOptions) {
|
||||||
const nodeBootstrap = globalThis.nodeBootstrap;
|
const nodeBootstrap = globalThis.nodeBootstrap;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
0: denoVersion,
|
0: location_,
|
||||||
1: location_,
|
1: unstableFlag,
|
||||||
2: tsVersion,
|
2: unstableFeatures,
|
||||||
3: unstableFlag,
|
3: inspectFlag,
|
||||||
4: unstableFeatures,
|
5: hasNodeModulesDir,
|
||||||
5: target,
|
6: maybeBinaryNpmCommandName,
|
||||||
6: v8Version,
|
|
||||||
7: inspectFlag,
|
|
||||||
9: hasNodeModulesDir,
|
|
||||||
10: maybeBinaryNpmCommandName,
|
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
performance.setTimeOrigin(DateNow());
|
performance.setTimeOrigin(DateNow());
|
||||||
|
@ -583,16 +586,12 @@ function bootstrapWorkerRuntime(
|
||||||
const nodeBootstrap = globalThis.nodeBootstrap;
|
const nodeBootstrap = globalThis.nodeBootstrap;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
0: denoVersion,
|
0: location_,
|
||||||
1: location_,
|
1: unstableFlag,
|
||||||
2: tsVersion,
|
2: unstableFeatures,
|
||||||
3: unstableFlag,
|
4: enableTestingFeaturesFlag,
|
||||||
4: unstableFeatures,
|
5: hasNodeModulesDir,
|
||||||
5: target,
|
6: maybeBinaryNpmCommandName,
|
||||||
6: v8Version,
|
|
||||||
8: enableTestingFeaturesFlag,
|
|
||||||
9: hasNodeModulesDir,
|
|
||||||
10: maybeBinaryNpmCommandName,
|
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
performance.setTimeOrigin(DateNow());
|
performance.setTimeOrigin(DateNow());
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use deno_core::op2;
|
use deno_core::op2;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::BootstrapOptions;
|
use crate::BootstrapOptions;
|
||||||
|
|
||||||
|
@ -16,9 +17,34 @@ deno_core::extension!(
|
||||||
op_bootstrap_log_level,
|
op_bootstrap_log_level,
|
||||||
op_bootstrap_no_color,
|
op_bootstrap_no_color,
|
||||||
op_bootstrap_is_tty,
|
op_bootstrap_is_tty,
|
||||||
|
op_snapshot_options,
|
||||||
],
|
],
|
||||||
|
options = {
|
||||||
|
snapshot_options: Option<SnapshotOptions>,
|
||||||
|
},
|
||||||
|
state = |state, options| {
|
||||||
|
if let Some(snapshot_options) = options.snapshot_options {
|
||||||
|
state.put::<SnapshotOptions>(snapshot_options);
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct SnapshotOptions {
|
||||||
|
pub deno_version: String,
|
||||||
|
pub ts_version: String,
|
||||||
|
pub v8_version: &'static str,
|
||||||
|
pub target: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: Called at snapshot time, op perf is not a concern.
|
||||||
|
#[op2]
|
||||||
|
#[serde]
|
||||||
|
pub fn op_snapshot_options(state: &mut OpState) -> SnapshotOptions {
|
||||||
|
state.take::<SnapshotOptions>()
|
||||||
|
}
|
||||||
|
|
||||||
#[op2]
|
#[op2]
|
||||||
#[serde]
|
#[serde]
|
||||||
pub fn op_bootstrap_args(state: &mut OpState) -> Vec<String> {
|
pub fn op_bootstrap_args(state: &mut OpState) -> Vec<String> {
|
||||||
|
|
|
@ -234,7 +234,7 @@ pub fn create_runtime_snapshot(snapshot_path: PathBuf) {
|
||||||
ops::signal::deno_signal::init_ops(),
|
ops::signal::deno_signal::init_ops(),
|
||||||
ops::tty::deno_tty::init_ops(),
|
ops::tty::deno_tty::init_ops(),
|
||||||
ops::http::deno_http_runtime::init_ops(),
|
ops::http::deno_http_runtime::init_ops(),
|
||||||
ops::bootstrap::deno_bootstrap::init_ops(),
|
ops::bootstrap::deno_bootstrap::init_ops(None),
|
||||||
];
|
];
|
||||||
|
|
||||||
for extension in &mut extensions {
|
for extension in &mut extensions {
|
||||||
|
|
|
@ -476,7 +476,7 @@ impl WebWorker {
|
||||||
ops::signal::deno_signal::init_ops_and_esm(),
|
ops::signal::deno_signal::init_ops_and_esm(),
|
||||||
ops::tty::deno_tty::init_ops_and_esm(),
|
ops::tty::deno_tty::init_ops_and_esm(),
|
||||||
ops::http::deno_http_runtime::init_ops_and_esm(),
|
ops::http::deno_http_runtime::init_ops_and_esm(),
|
||||||
ops::bootstrap::deno_bootstrap::init_ops_and_esm(),
|
ops::bootstrap::deno_bootstrap::init_ops_and_esm(None),
|
||||||
deno_permissions_web_worker::init_ops_and_esm(
|
deno_permissions_web_worker::init_ops_and_esm(
|
||||||
permissions,
|
permissions,
|
||||||
enable_testing_features,
|
enable_testing_features,
|
||||||
|
|
|
@ -380,7 +380,7 @@ impl MainWorker {
|
||||||
ops::signal::deno_signal::init_ops_and_esm(),
|
ops::signal::deno_signal::init_ops_and_esm(),
|
||||||
ops::tty::deno_tty::init_ops_and_esm(),
|
ops::tty::deno_tty::init_ops_and_esm(),
|
||||||
ops::http::deno_http_runtime::init_ops_and_esm(),
|
ops::http::deno_http_runtime::init_ops_and_esm(),
|
||||||
ops::bootstrap::deno_bootstrap::init_ops_and_esm(),
|
ops::bootstrap::deno_bootstrap::init_ops_and_esm(None),
|
||||||
deno_permissions_worker::init_ops_and_esm(
|
deno_permissions_worker::init_ops_and_esm(
|
||||||
permissions,
|
permissions,
|
||||||
enable_testing_features,
|
enable_testing_features,
|
||||||
|
|
|
@ -51,10 +51,6 @@ pub struct BootstrapOptions {
|
||||||
/// Sets `Deno.noColor` in JS runtime.
|
/// Sets `Deno.noColor` in JS runtime.
|
||||||
pub no_color: bool,
|
pub no_color: bool,
|
||||||
pub is_tty: 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,
|
|
||||||
// --unstable flag, deprecated
|
// --unstable flag, deprecated
|
||||||
pub unstable: bool,
|
pub unstable: bool,
|
||||||
// --unstable-* flags
|
// --unstable-* flags
|
||||||
|
@ -71,11 +67,10 @@ impl Default for BootstrapOptions {
|
||||||
.map(|p| p.get())
|
.map(|p| p.get())
|
||||||
.unwrap_or(1);
|
.unwrap_or(1);
|
||||||
|
|
||||||
let runtime_version = env!("CARGO_PKG_VERSION").into();
|
let runtime_version = env!("CARGO_PKG_VERSION");
|
||||||
let user_agent = format!("Deno/{runtime_version}");
|
let user_agent = format!("Deno/{runtime_version}");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
runtime_version,
|
|
||||||
user_agent,
|
user_agent,
|
||||||
cpu_count,
|
cpu_count,
|
||||||
no_color: !colors::use_color(),
|
no_color: !colors::use_color(),
|
||||||
|
@ -83,7 +78,6 @@ impl Default for BootstrapOptions {
|
||||||
enable_op_summary_metrics: Default::default(),
|
enable_op_summary_metrics: Default::default(),
|
||||||
enable_testing_features: Default::default(),
|
enable_testing_features: Default::default(),
|
||||||
log_level: Default::default(),
|
log_level: Default::default(),
|
||||||
ts_version: Default::default(),
|
|
||||||
locale: "en".to_string(),
|
locale: "en".to_string(),
|
||||||
location: Default::default(),
|
location: Default::default(),
|
||||||
unstable: Default::default(),
|
unstable: Default::default(),
|
||||||
|
@ -107,20 +101,12 @@ impl Default for BootstrapOptions {
|
||||||
/// Keep this in sync with `99_main.js`.
|
/// Keep this in sync with `99_main.js`.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct BootstrapV8<'a>(
|
struct BootstrapV8<'a>(
|
||||||
// runtime_version
|
|
||||||
&'a str,
|
|
||||||
// location
|
// location
|
||||||
Option<&'a str>,
|
Option<&'a str>,
|
||||||
// ts_version
|
|
||||||
&'a str,
|
|
||||||
// unstable
|
// unstable
|
||||||
bool,
|
bool,
|
||||||
// granular unstable flags
|
// granular unstable flags
|
||||||
&'a [i32],
|
&'a [i32],
|
||||||
// env!("TARGET")
|
|
||||||
&'a str,
|
|
||||||
// v8_version
|
|
||||||
&'a str,
|
|
||||||
// inspect
|
// inspect
|
||||||
bool,
|
bool,
|
||||||
// enable_testing_features
|
// enable_testing_features
|
||||||
|
@ -141,13 +127,9 @@ impl BootstrapOptions {
|
||||||
let ser = deno_core::serde_v8::Serializer::new(&scope);
|
let ser = deno_core::serde_v8::Serializer::new(&scope);
|
||||||
|
|
||||||
let bootstrap = BootstrapV8(
|
let bootstrap = BootstrapV8(
|
||||||
&self.runtime_version,
|
|
||||||
self.location.as_ref().map(|l| l.as_str()),
|
self.location.as_ref().map(|l| l.as_str()),
|
||||||
&self.ts_version,
|
|
||||||
self.unstable,
|
self.unstable,
|
||||||
self.unstable_features.as_ref(),
|
self.unstable_features.as_ref(),
|
||||||
env!("TARGET"),
|
|
||||||
deno_core::v8_version(),
|
|
||||||
self.inspect,
|
self.inspect,
|
||||||
self.enable_testing_features,
|
self.enable_testing_features,
|
||||||
self.has_node_modules_dir,
|
self.has_node_modules_dir,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue