GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Report event dispatches to the dependency graph as emitEvent by Domiii · Pull Request #242 · replayio/node

Conversation

@Domiii

@Domiii Domiii commented Nov 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🤖

  • follows Report async work to the dependency graph #240
  • paired w/ https://github.com/replayio/backend/pull/13927
  • REPLAY_BACKEND_REV → backend master 5d351da35be9: the emitEvent kind (backend#13927) and node-recording on the shared fixture (backend#13925).

Summary

  • Problem: node event dispatches are not in the dependency graph.
    • Work a listener schedules depends on whatever execution happens to enclose the emit.
  • Solution: every dispatch with listeners runs its listener calls in an execution of a new emitEvent{type} node.
    • Chains through stream and socket events now name the event, e.g. emitEvent(data).

Kind

  • emitEvent{type}, added to the backend by backend#13927.
  • Not Chromium's dispatchEvent, because the backend reads dispatchEvent as DOM input.
    • dependencyGraph.ts knownOriginNode ends chains at dispatchEvent of input types: click, change, keypress, input, submit, …
    • Node emits those names outside of input: fs.watch 'change', readline 'keypress', user emitters.
  • emitEvent is not an origin. Chains continue through its execution parent, e.g. asyncCallback.

Sites

  • EventEmitter.prototype.emit, once a handler exists
    • Every node-style emitter dispatches here, including streams, sockets and process.
  • EventTarget kHybridDispatch, once listeners exist
    • dispatchEvent, NodeEventTarget#emit and MessagePort messages all call it.
  • Both: begin(type); try { listener calls } finally { end() }.

Dependency executions

  • One primitive, DependencyExecution, in src/node_dependency_graph.h:
    • Begin: save the execution depth. Begin an execution only if there is a node.
    • End: unwind to the saved depth.
      • This also ends executions begun inside it whose own end was skipped.
  • The async_hooks windows of node#240 and the dispatches both use it.
  • Dispatches live on a C++ stack.
    • Nothing is returned to JS. So JS sees the same values when recording and replaying.
    • A dispatch without a node, before the first checkpoint, keeps an entry that never began. So an end always pops its own entry.
  • A window pop also drops the dispatches its unwind ended.
    • Example: a termination skips the finally of a dispatch. The dispatch then ends with its window.
  • An end first drops dispatches that an unwind already ended. Then it ends the innermost remaining one.

Event type

  • Strings are reported as is.
  • Symbols are reported by their description, or "" without one.
  • Other values are reported as "".
    • Converting them could run user toString in replay only.

Gates

  • Same as node#240.
  • JS gate: the boolean in internal/async_hooks, read once in prepareExecution.
    • Unrecorded runs: 2 checks of a false boolean per dispatch with listeners. 0 binding calls.
    • Recordings: 2 binding calls per dispatch with listeners.
  • C++ gate: DependencyGraphEnabled().
    • Nodes and dispatch entries exist only while it holds.

Upstream merge surface

  • emit: the single-listener branch is re-indented into a try. The multi-listener branch ends the dispatch in its existing finally.
  • kHybridDispatch: the listener loop is re-indented into a try.
    • The other options both cost something:
      • A helper function adds a call and a JS-visible stack frame on the unrecorded path.
      • Dropping the finally leaves the dispatch open after an exception.
  • Expect conflicts there when merging upstream node.

Data

  • Build linux-node-20261117-ba57434f2507-5d351da35be9-dev, from BK runtime-node-build-and-test Windows Installer does not broadcast a WM_SETTINGCHANGE nodejs/node#603, the top of this stack.
  • Benchmark: 1e6 EventEmitter#emit and 1e5 EventTarget#dispatchEvent, one listener each. Recorded. Medians of 3 runs, ms:
run emit ×1e6 dispatchEvent ×1e5
recorded 78 89
recorded, RECORD_REPLAY_DISABLE_FEATURES=["dependency-graph"] 59 82
unrecorded (RECORD_REPLAY_DONT_RECORD=1), main nodejs#596, median of 5 23 17
unrecorded, nodejs#603, median of 5 24 15
  • Cost, as rate × scale:
    • Recordings: about 19 ns more per emit and about 70 ns more per dispatchEvent.
    • Unrecorded runs: within noise.
  • Replay of dependency-graph/await-fetch in test-node-recording, ms:
build case time
main nodejs#596, node#240 only 2718
nodejs#602, this PR 2697
nodejs#603, top of the stack 2607
  • Not measured: the dependency graph's node count.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Domiii
Report event dispatches to the dependency graph
f098509
The listener calls of EventEmitter#emit and of EventTarget dispatches run
in a dependency execution of a dispatchEvent{type} node, the kind Chromium
reports synchronous event dispatch with. So the work a listener schedules
depends on the dispatch, and the chain continues to the callback that
emitted it.

- Sites: EventEmitter.prototype.emit once a handler exists, and
  EventTarget's kHybridDispatch once listeners exist, which dispatchEvent,
  NodeEventTarget#emit and MessagePort messages share. The calls end in a
  finally.
- The depths before each dispatch begins stay on a C++ stack. An end drops
  the dispatches an outer unwind already ended and unwinds to the innermost
  remaining one. Nothing is returned to JS.
- type: a string, or a Symbol's description. Other values are not
  converted, which could run JS.

Prod behavior. Unrecorded runs: two checks of a false boolean per dispatch
with listeners, no binding calls. Recordings: two binding calls per
dispatch, which return after checking a cached flag; nodes and depths only
exist when replaying. No JS-visible change.
@Domiii Domiii self-assigned this Nov 17, 2026
@Domiii
Domiii added this pull request to stack #245 November 17, 2026 17:15
@Domiii Domiii mentioned this pull request Nov 17, 2026
Report process.nextTick() as a microtask to the dependency graph #243
Merged
@Domiii
Report node event dispatches as emitEvent; share one dependency execu…
72a2473
…tion primitive

- Kind emitEvent{type} instead of dispatchEvent{type}. The backend reads
  dispatchEvent of input types (click, change, keypress, ...) as a DOM
  input origin and ends chains there; node emits those names outside of
  input (fs.watch 'change', readline 'keypress', user emitters).
- DependencyExecution: save the depth, begin iff there is a node, end by
  unwinding to the depth. Windows and dispatches use it.
- A window pop also drops the dispatches its unwind ended, so a dispatch
  whose finally a termination skipped does not outlive its window.
- Dispatches without a node keep a nullopt entry, so an end pops exactly
  its own entry.
- EventEmitter#emit: no re-indent of the multi-listener body; the dispatch
  ends in its existing finally.
@Domiii Domiii changed the title Report event dispatches to the dependency graph Report event dispatches to the dependency graph as emitEvent Nov 17, 2026
@Domiii
Pin REPLAY_BACKEND_REV to backend with the node emitEvent kind (backe…
f810dc9
…nd#13927) and B1b (backend#13925)
@Domiii
Domiii merged commit 7f7fff0 into main Nov 17, 2026
3 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@Domiii
Domiii deleted the dominik/node-dg-events branch November 17, 2026 19:44
@Domiii Domiii mentioned this pull request Nov 18, 2026
Dependency graph: unmodified emit and [kHybridDispatch], folded gates in uninstrumented processes #250
Merged
Domiii added a commit that referenced this pull request Nov 18, 2026
@Domiii
EventTarget: install the dependency graph dispatch over an unmodified…
e3fb731
… [kHybridDispatch]

[kHybridDispatch] is the pre-#242 code again. When instrumented,
pre-execution installs hybridDispatchInDependencyGraph(), which runs the
original in the emitEvent node's Begin/End if it has listeners.
Domiii added a commit that referenced this pull request Nov 18, 2026
@Domiii
Events: install the dependency graph dispatches over unmodified emit …
64b4f9e
…and [kHybridDispatch]

EventEmitter#emit and EventTarget[kHybridDispatch] are the pre-#242 code
again. When instrumented, pre-execution installs wrappers from
internal/events/dependency_graph that run the original in the emitEvent
node's Begin/End iff it calls listeners. emit('error') with kErrorMonitor
listeners now emits kErrorMonitor inside the 'error' dispatch.
Domiii added a commit that referenced this pull request Nov 18, 2026
@Domiii
Dependency graph: unmodified emit and [kHybridDispatch], folded gates…
d8d1719
… in uninstrumented processes (#250)

* Dependency graph: fold the instrumented checks of uninstrumented processes

The checks read a let of internal/async_hooks, which optimized code loads
and converts to a boolean at every check: in EventEmitter#emit, twice per
call. A field of a constant object, written only when it changes, is folded
to its value instead. emit() of a single listener moves its try/finally to
a function called only when instrumented.

* EventTarget: end the dispatch in a catch, not a finally

A finally costs on the normal path also when not instrumented. Listener
errors are caught in the loop, so only internal errors reach the catch.

* EventTarget: keep the finally; emit(): explain the duplicated listener call

The catch ending an EventTarget dispatch rethrew with a new message
location. With the gates folded, the finally remains the only cost.

* EventTarget: dispatch outside of the try/finally when not instrumented

The listener loop moves to dispatchListeners(). Instrumented, it runs in
dispatchInDependencyGraph()'s try/finally; else kHybridDispatch calls it
directly.

* EventTarget: keep the dispatch loop in kHybridDispatch

dispatchListeners() was inlined into dispatchEvent(), which slowed
dispatches down.

* EventTarget: install the dependency graph dispatch over an unmodified [kHybridDispatch]

[kHybridDispatch] is the pre-#242 code again. When instrumented,
pre-execution installs hybridDispatchInDependencyGraph(), which runs the
original in the emitEvent node's Begin/End if it has listeners.

* Events: install the dependency graph dispatches over unmodified emit and [kHybridDispatch]

EventEmitter#emit and EventTarget[kHybridDispatch] are the pre-#242 code
again. When instrumented, pre-execution installs wrappers from
internal/events/dependency_graph that run the original in the emitEvent
node's Begin/End iff it calls listeners. emit('error') with kErrorMonitor
listeners now emits kErrorMonitor inside the 'error' dispatch.

* Events: define the dependency graph dispatch rule in the wrapper

A call dispatches iff type is a string or symbol and the emitter or target
has a listener for type at call time. Deciding it runs no user code.

* Events: state the dependency graph dispatch decision's reads exactly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Domiii Domiii

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Domiii
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.