summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-09-17 15:34:43 +0530
committerGitHub <noreply@github.com>2022-09-17 15:34:43 +0530
commit6154188786108b253e8c775f728783e9ffa5293f (patch)
treec39fd66203fe839d67dbd34309c5045abf1ce1ed
parente7934432ced9674d23d31a4b6973398bd8c8d090 (diff)
perf(ext/console): avoid `wrapConsole` when not inspecting (#15931)
-rw-r--r--cli/bench/console.js8
-rw-r--r--cli/standalone.rs1
-rw-r--r--cli/tests/testdata/event_listener_error_immediate_exit.ts.out1
-rw-r--r--cli/worker.rs2
-rw-r--r--runtime/examples/hello_runtime.rs1
-rw-r--r--runtime/js/99_main.js7
-rw-r--r--runtime/worker.rs1
-rw-r--r--runtime/worker_bootstrap.rs2
8 files changed, 21 insertions, 2 deletions
diff --git a/cli/bench/console.js b/cli/bench/console.js
new file mode 100644
index 000000000..b1873953c
--- /dev/null
+++ b/cli/bench/console.js
@@ -0,0 +1,8 @@
+// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+const count = 100000;
+
+const start = Date.now();
+for (let i = 0; i < count; i++) console.log("Hello World");
+const elapsed = Date.now() - start;
+const rate = Math.floor(count / (elapsed / 1000));
+console.log(`time ${elapsed} ms rate ${rate}`);
diff --git a/cli/standalone.rs b/cli/standalone.rs
index fa5fffd13..65a51fde5 100644
--- a/cli/standalone.rs
+++ b/cli/standalone.rs
@@ -283,6 +283,7 @@ pub async fn run(
ts_version: version::TYPESCRIPT.to_string(),
unstable: metadata.unstable,
user_agent: version::get_user_agent(),
+ inspect: ps.options.is_inspecting(),
},
extensions: ops::cli_exts(ps.clone()),
unsafely_ignore_certificate_errors: metadata
diff --git a/cli/tests/testdata/event_listener_error_immediate_exit.ts.out b/cli/tests/testdata/event_listener_error_immediate_exit.ts.out
index 8f03f71b8..1fb3ce76a 100644
--- a/cli/tests/testdata/event_listener_error_immediate_exit.ts.out
+++ b/cli/tests/testdata/event_listener_error_immediate_exit.ts.out
@@ -1,4 +1,5 @@
1
+queueMicrotask
error: Uncaught Error: bar
throw new Error("bar");
^
diff --git a/cli/worker.rs b/cli/worker.rs
index 9b505e4f0..f46c2efce 100644
--- a/cli/worker.rs
+++ b/cli/worker.rs
@@ -410,6 +410,7 @@ pub async fn create_main_worker(
ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.options.unstable(),
user_agent: version::get_user_agent(),
+ inspect: ps.options.is_inspecting(),
},
extensions,
unsafely_ignore_certificate_errors: ps
@@ -515,6 +516,7 @@ fn create_web_worker_callback(
ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.options.unstable(),
user_agent: version::get_user_agent(),
+ inspect: ps.options.is_inspecting(),
},
extensions,
unsafely_ignore_certificate_errors: ps
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs
index d941cdd05..de5c2427d 100644
--- a/runtime/examples/hello_runtime.rs
+++ b/runtime/examples/hello_runtime.rs
@@ -39,6 +39,7 @@ async fn main() -> Result<(), AnyError> {
ts_version: "x".to_string(),
unstable: false,
user_agent: "hello_runtime".to_string(),
+ inspect: false,
},
extensions: vec![],
unsafely_ignore_certificate_errors: None,
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index b25022a08..27dc7111a 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -648,6 +648,7 @@ delete Intl.v8BreakIterator;
ppid,
unstableFlag,
cpuCount,
+ inspectFlag,
userAgent: userAgentInfo,
} = runtimeOptions;
@@ -679,8 +680,10 @@ delete Intl.v8BreakIterator;
ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties);
ObjectSetPrototypeOf(globalThis, Window.prototype);
- const consoleFromDeno = globalThis.console;
- wrapConsole(consoleFromDeno, consoleFromV8);
+ if (inspectFlag) {
+ const consoleFromDeno = globalThis.console;
+ wrapConsole(consoleFromDeno, consoleFromV8);
+ }
eventTarget.setEventTargetData(globalThis);
diff --git a/runtime/worker.rs b/runtime/worker.rs
index bce30b88e..82b6a589e 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -511,6 +511,7 @@ mod tests {
ts_version: "x".to_string(),
unstable: false,
user_agent: "x".to_string(),
+ inspect: false,
},
extensions: vec![],
unsafely_ignore_certificate_errors: None,
diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs
index 68f223be5..31e7c4382 100644
--- a/runtime/worker_bootstrap.rs
+++ b/runtime/worker_bootstrap.rs
@@ -21,6 +21,7 @@ pub struct BootstrapOptions {
pub ts_version: String,
pub unstable: bool,
pub user_agent: String,
+ pub inspect: bool,
}
impl BootstrapOptions {
@@ -44,6 +45,7 @@ impl BootstrapOptions {
"target": env!("TARGET"),
"v8Version": deno_core::v8_version(),
"userAgent": self.user_agent,
+ "inspectFlag": self.inspect,
});
serde_json::to_string_pretty(&payload).unwrap()
}