summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-11-15 04:25:55 -0800
committerGitHub <noreply@github.com>2023-11-15 13:25:55 +0100
commit7f3902b41f68edddbc50b01ea52c697827d8516f (patch)
tree4fae66aafc0d4c81e9fa39d7e2e2117f1afcf551 /runtime
parentc67de43ff3221ae5554398095261d684b6d41dda (diff)
perf: static bootstrap options in snapshot (#21213)
Closes https://github.com/denoland/deno/issues/21133
Diffstat (limited to 'runtime')
-rw-r--r--runtime/js/99_main.js39
-rw-r--r--runtime/ops/bootstrap.rs26
-rw-r--r--runtime/snapshot.rs2
-rw-r--r--runtime/web_worker.rs2
-rw-r--r--runtime/worker.rs2
-rw-r--r--runtime/worker_bootstrap.rs20
6 files changed, 49 insertions, 42 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 76a279bbd..89296d632 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -450,6 +450,13 @@ const finalDenoNs = {
...denoNs,
};
+const {
+ denoVersion,
+ tsVersion,
+ v8Version,
+ target,
+} = ops.op_snapshot_options();
+
function bootstrapMainRuntime(runtimeOptions) {
if (hasBootstrapped) {
throw new Error("Worker runtime already bootstrapped");
@@ -457,16 +464,12 @@ function bootstrapMainRuntime(runtimeOptions) {
const nodeBootstrap = globalThis.nodeBootstrap;
const {
- 0: denoVersion,
- 1: location_,
- 2: tsVersion,
- 3: unstableFlag,
- 4: unstableFeatures,
- 5: target,
- 6: v8Version,
- 7: inspectFlag,
- 9: hasNodeModulesDir,
- 10: maybeBinaryNpmCommandName,
+ 0: location_,
+ 1: unstableFlag,
+ 2: unstableFeatures,
+ 3: inspectFlag,
+ 5: hasNodeModulesDir,
+ 6: maybeBinaryNpmCommandName,
} = runtimeOptions;
performance.setTimeOrigin(DateNow());
@@ -583,16 +586,12 @@ function bootstrapWorkerRuntime(
const nodeBootstrap = globalThis.nodeBootstrap;
const {
- 0: denoVersion,
- 1: location_,
- 2: tsVersion,
- 3: unstableFlag,
- 4: unstableFeatures,
- 5: target,
- 6: v8Version,
- 8: enableTestingFeaturesFlag,
- 9: hasNodeModulesDir,
- 10: maybeBinaryNpmCommandName,
+ 0: location_,
+ 1: unstableFlag,
+ 2: unstableFeatures,
+ 4: enableTestingFeaturesFlag,
+ 5: hasNodeModulesDir,
+ 6: maybeBinaryNpmCommandName,
} = runtimeOptions;
performance.setTimeOrigin(DateNow());
diff --git a/runtime/ops/bootstrap.rs b/runtime/ops/bootstrap.rs
index 72e31a1d6..066488d09 100644
--- a/runtime/ops/bootstrap.rs
+++ b/runtime/ops/bootstrap.rs
@@ -2,6 +2,7 @@
use deno_core::op2;
use deno_core::OpState;
+use serde::Serialize;
use crate::BootstrapOptions;
@@ -16,9 +17,34 @@ deno_core::extension!(
op_bootstrap_log_level,
op_bootstrap_no_color,
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]
#[serde]
pub fn op_bootstrap_args(state: &mut OpState) -> Vec<String> {
diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs
index 61b0e075f..6ac50dca1 100644
--- a/runtime/snapshot.rs
+++ b/runtime/snapshot.rs
@@ -234,7 +234,7 @@ pub fn create_runtime_snapshot(snapshot_path: PathBuf) {
ops::signal::deno_signal::init_ops(),
ops::tty::deno_tty::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 {
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index 54cafe87b..cd5458109 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -476,7 +476,7 @@ impl WebWorker {
ops::signal::deno_signal::init_ops_and_esm(),
ops::tty::deno_tty::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(
permissions,
enable_testing_features,
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 9a9802c12..a3882bf20 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -380,7 +380,7 @@ impl MainWorker {
ops::signal::deno_signal::init_ops_and_esm(),
ops::tty::deno_tty::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(
permissions,
enable_testing_features,
diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs
index 3bcf45dd0..828bb3766 100644
--- a/runtime/worker_bootstrap.rs
+++ b/runtime/worker_bootstrap.rs
@@ -51,10 +51,6 @@ pub struct BootstrapOptions {
/// 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,
// --unstable flag, deprecated
pub unstable: bool,
// --unstable-* flags
@@ -71,11 +67,10 @@ impl Default for BootstrapOptions {
.map(|p| p.get())
.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}");
Self {
- runtime_version,
user_agent,
cpu_count,
no_color: !colors::use_color(),
@@ -83,7 +78,6 @@ impl Default for BootstrapOptions {
enable_op_summary_metrics: Default::default(),
enable_testing_features: Default::default(),
log_level: Default::default(),
- ts_version: Default::default(),
locale: "en".to_string(),
location: Default::default(),
unstable: Default::default(),
@@ -107,20 +101,12 @@ impl Default for BootstrapOptions {
/// Keep this in sync with `99_main.js`.
#[derive(Serialize)]
struct BootstrapV8<'a>(
- // runtime_version
- &'a str,
// location
Option<&'a str>,
- // ts_version
- &'a str,
// unstable
bool,
// granular unstable flags
&'a [i32],
- // env!("TARGET")
- &'a str,
- // v8_version
- &'a str,
// inspect
bool,
// enable_testing_features
@@ -141,13 +127,9 @@ impl BootstrapOptions {
let ser = deno_core::serde_v8::Serializer::new(&scope);
let bootstrap = BootstrapV8(
- &self.runtime_version,
self.location.as_ref().map(|l| l.as_str()),
- &self.ts_version,
self.unstable,
self.unstable_features.as_ref(),
- env!("TARGET"),
- deno_core::v8_version(),
self.inspect,
self.enable_testing_features,
self.has_node_modules_dir,