mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
perf: don't add unload event listener (#18082)
This commit changes how "unload" event is handled - before this commit an event listener was added unconditionally in the runtime bootstrapping function, which for some reason was very expensive (0.3ms). Instead of adding an event listener, a check was added to "dispatchEvent" function that performs the same action (so it's only called if there's an event dispatched).
This commit is contained in:
parent
25d98ca289
commit
0f9df73349
2 changed files with 9 additions and 11 deletions
|
@ -1056,6 +1056,15 @@ class EventTarget {
|
|||
prefix: "Failed to execute 'dispatchEvent' on 'EventTarget'",
|
||||
});
|
||||
|
||||
// This is an optimization to avoid creating an event listener
|
||||
// on each startup.
|
||||
// Stores the flag for checking whether unload is dispatched or not.
|
||||
// This prevents the recursive dispatches of unload events.
|
||||
// See https://github.com/denoland/deno/issues/9201.
|
||||
if (event.type === "unload" && self === globalThis_) {
|
||||
globalThis_[SymbolFor("isUnloadDispatched")] = true;
|
||||
}
|
||||
|
||||
const { listeners } = self[eventTargetData];
|
||||
if (!ReflectHas(listeners, event.type)) {
|
||||
setTarget(event, this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue