Skip to content

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Sep 15, 2025

Required for denoland/deno#30743

This commit changes LocalInspectorSession to only provide a
sync API.

While it might feel counterintuitive, as it is now the callers responsibility
to handle request/response cycles, this change actually greatly
simplifies inspector implementation and gives granular control
over behavior of inspector. The main change is that sync sessions, no
longer require event loop ticks to make progress - ie. sending a message
is fully synchronous - because there no channels involved. This leads
to the fact that "responses" (which are actually callbacks) are most
often produces when the message is sent and returned.

Thanks to this change, it's now possible to easily implement interactions
with V8 coverage collection and profiler inspector domains.

@bartlomieju
Copy link
Member Author

bartlomieju commented Sep 15, 2025

Open to bike-shedding on the name - I'm also fine just renaming the struct and stripping it out of its async API.

This is a first in the series of PRs that are simplifying inspector implementation - see #1192 for next steps

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 62.19512% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.57%. Comparing base (0c7f83e) to head (a1c1b47).
⚠️ Report is 336 commits behind head on main.

Files with missing lines Patch % Lines
core/inspector.rs 73.91% 18 Missing ⚠️
dcore/src/inspector_server.rs 0.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1193      +/-   ##
==========================================
- Coverage   81.43%   79.57%   -1.86%     
==========================================
  Files          97      100       +3     
  Lines       23877    25841    +1964     
==========================================
+ Hits        19445    20564    +1119     
- Misses       4432     5277     +845     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

.borrow()
.create_local_session(session_options);
let inspector = runtime.inspector();
let (tx, rx) = std::sync::mpsc::channel();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should probably be oneshot?

notification_rx: Option<UnboundedReceiver<Value>>,
///
/// Does not provide any abstraction over CDP messages.
pub struct LocalSyncInspectorSession {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you could keep this being named LocalInspectorSession

@bartlomieju bartlomieju changed the title feat: Add LocalSyncInspectorSession and remove LocalInspectorSession feat(BREAKING): Make LocalInspectorSession synchronous Sep 16, 2025
@bartlomieju bartlomieju enabled auto-merge (squash) September 16, 2025 11:20
@bartlomieju bartlomieju merged commit 63d156c into denoland:main Sep 16, 2025
18 checks passed
@bartlomieju bartlomieju deleted the sync_inspector2 branch September 16, 2025 11:49
bartlomieju added a commit that referenced this pull request Sep 17, 2025
Fixing some of the fall out from
#1193.

Testing in CLI it turned out that there's a double RefCell borrow panic
occuring, when running the REPL - when the exception was raised when evaluating an
expression - and said expression was evaluated as part of dispatching an inspector
message - the `op_dispatch_exception` op was called that tries to mutable borrow
the inspector instance.

This is now avoided by storing `SessionContainer` in the
`LocalInspectorSession`, instead of `JsRuntimeInspector`.

This will be further simplified in follow up PRs like
#1192.
bartlomieju added a commit to denoland/deno that referenced this pull request Sep 17, 2025
Based on denoland/deno_core#1193.

This commit rewrites 3 parts of the system to use a new "sync"
V8 inspector API exposed by `deno_core`:
- REPL
- coverage collection
- hot module replacement

Turns out the async abstraction over V8 inspector was unnecessary
and actually greatly complicated usage of the inspector.

Towards #13572
Towards #13206
Tango992 pushed a commit to Tango992/deno that referenced this pull request Sep 24, 2025
Based on denoland/deno_core#1193.

This commit rewrites 3 parts of the system to use a new "sync"
V8 inspector API exposed by `deno_core`:
- REPL
- coverage collection
- hot module replacement

Turns out the async abstraction over V8 inspector was unnecessary
and actually greatly complicated usage of the inspector.

Towards denoland#13572
Towards denoland#13206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants