Skip to content

Commit

Permalink
perf(ext/console): avoid wrapConsole when not inspecting (#15931)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Sep 17, 2022
1 parent e793443 commit 6154188
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cli/bench/console.js
Original file line number Diff line number Diff line change
@@ -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}`);
1 change: 1 addition & 0 deletions cli/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1
queueMicrotask
error: Uncaught Error: bar
throw new Error("bar");
^
Expand Down
2 changes: 2 additions & 0 deletions cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/examples/hello_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ delete Intl.v8BreakIterator;
ppid,
unstableFlag,
cpuCount,
inspectFlag,
userAgent: userAgentInfo,
} = runtimeOptions;

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions runtime/worker_bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct BootstrapOptions {
pub ts_version: String,
pub unstable: bool,
pub user_agent: String,
pub inspect: bool,
}

impl BootstrapOptions {
Expand All @@ -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()
}
Expand Down

0 comments on commit 6154188

Please sign in to comment.