1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

perf(core): do not drive JsInspector by default (#16410)

Part of https://github.com/denoland/deno/pull/16377
This commit is contained in:
Divy Srivastava 2022-10-26 17:07:50 +05:30 committed by GitHub
parent 4d166e638f
commit 851db03a6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 10 deletions

View file

@ -766,6 +766,10 @@ fn op_dispatch_exception(
.dispatched_exceptions
.push_front(v8::Global::new(scope, exception.v8_value));
// Only terminate execution if there are no inspector sessions.
if state.inspector.is_none() {
scope.terminate_execution();
return;
}
match state.inspector().try_borrow() {
Ok(inspector) if !inspector.has_active_sessions() => {
scope.terminate_execution();

View file

@ -180,7 +180,7 @@ pub struct JsRuntimeState {
// TODO(nayeemrmn): This is polled in `exception_to_err_result()` which is
// flimsy. Try to poll it similarly to `pending_promise_exceptions`.
pub(crate) dispatched_exceptions: VecDeque<v8::Global<v8::Value>>,
inspector: Option<Rc<RefCell<JsRuntimeInspector>>>,
pub(crate) inspector: Option<Rc<RefCell<JsRuntimeInspector>>>,
waker: AtomicWaker,
}
@ -275,6 +275,7 @@ pub struct RuntimeOptions {
/// [CompiledWasmModuleStore]. If no [CompiledWasmModuleStore] is specified,
/// `WebAssembly.Module` objects cannot be serialized.
pub compiled_wasm_module_store: Option<CompiledWasmModuleStore>,
pub inspector: bool,
}
impl Drop for JsRuntime {
@ -429,8 +430,14 @@ impl JsRuntime {
};
op_state.borrow_mut().put(isolate_ptr);
let inspector =
JsRuntimeInspector::new(&mut isolate, global_context.clone());
let inspector = if options.inspector {
Some(JsRuntimeInspector::new(
&mut isolate,
global_context.clone(),
))
} else {
None
};
let loader = options
.module_loader
@ -439,7 +446,7 @@ impl JsRuntime {
let mut state = state_rc.borrow_mut();
state.global_realm = Some(JsRealm(global_context));
state.op_ctxs = op_ctxs;
state.inspector = Some(inspector);
state.inspector = inspector;
}
isolate.set_data(
Self::STATE_DATA_OFFSET,
@ -901,6 +908,18 @@ impl JsRuntime {
}
}
pub fn maybe_init_inspector(&mut self) {
if self.state.borrow().inspector.is_some() {
return;
}
let mut state = self.state.borrow_mut();
state.inspector = Some(JsRuntimeInspector::new(
self.v8_isolate.as_mut().unwrap(),
state.global_realm.clone().unwrap().0,
));
}
pub fn poll_value(
&mut self,
global: &v8::Global<v8::Value>,
@ -970,13 +989,19 @@ impl JsRuntime {
cx: &mut Context,
wait_for_inspector: bool,
) -> Poll<Result<(), Error>> {
// We always poll the inspector first
let _ = self.inspector().borrow_mut().poll_unpin(cx);
let has_inspector: bool;
{
let state = self.state.borrow();
has_inspector = state.inspector.is_some();
state.waker.register(cx.waker());
}
if has_inspector {
// We poll the inspector first.
let _ = self.inspector().borrow_mut().poll_unpin(cx);
}
self.pump_v8_message_loop()?;
// Ops
@ -1030,10 +1055,12 @@ impl JsRuntime {
let pending_state = self.event_loop_pending_state();
if !pending_state.is_pending() && !maybe_scheduling {
let inspector_has_active_sessions =
self.inspector().borrow_mut().has_active_sessions();
if wait_for_inspector && inspector_has_active_sessions {
return Poll::Pending;
if has_inspector {
let inspector_has_active_sessions =
self.inspector().borrow_mut().has_active_sessions();
if wait_for_inspector && inspector_has_active_sessions {
return Poll::Pending;
}
}
return Poll::Ready(Ok(()));

View file

@ -457,6 +457,7 @@ impl WebWorker {
shared_array_buffer_store: options.shared_array_buffer_store.clone(),
compiled_wasm_module_store: options.compiled_wasm_module_store.clone(),
extensions,
inspector: options.maybe_inspector_server.is_some(),
..Default::default()
});

View file

@ -248,6 +248,7 @@ impl MainWorker {
shared_array_buffer_store: options.shared_array_buffer_store.clone(),
compiled_wasm_module_store: options.compiled_wasm_module_store.clone(),
extensions,
inspector: options.maybe_inspector_server.is_some(),
..Default::default()
});
@ -441,6 +442,7 @@ impl MainWorker {
/// Create new inspector session. This function panics if Worker
/// was not configured to create inspector.
pub async fn create_inspector_session(&mut self) -> LocalInspectorSession {
self.js_runtime.maybe_init_inspector();
self.js_runtime.inspector().borrow().create_local_session()
}