Skip to content

Commit 43aa76e

Browse files
committed
lib: speed up MessageEvent creation internally
1 parent d78537b commit 43aa76e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/internal/worker/io.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ const messageTypes = {
8585
LOAD_SCRIPT: 'loadScript',
8686
};
8787

88-
let messageEvent;
89-
function lazyMessageEvent() {
90-
return messageEvent ??= require('internal/deps/undici/undici').MessageEvent;
88+
let fastCreateMessageEvent;
89+
function lazyMessageEvent(type, init) {
90+
fastCreateMessageEvent ??= require('internal/deps/undici/undici').createFastMessageEvent;
91+
return fastCreateMessageEvent(type, init);
9192
}
9293

9394
// We have to mess with the MessagePort prototype a bit, so that a) we can make
@@ -128,7 +129,7 @@ ObjectDefineProperty(
128129
}
129130
const ports = this[kCurrentlyReceivingPorts];
130131
this[kCurrentlyReceivingPorts] = undefined;
131-
return new (lazyMessageEvent())(type, { data, ports });
132+
return lazyMessageEvent(type, { data, ports });
132133
},
133134
configurable: false,
134135
writable: false,
@@ -321,7 +322,7 @@ function receiveMessageOnPort(port) {
321322
}
322323

323324
function onMessageEvent(type, data) {
324-
this.dispatchEvent(new (lazyMessageEvent())(type, { data }));
325+
this.dispatchEvent(lazyMessageEvent(type, { data }));
325326
}
326327

327328
function isBroadcastChannel(value) {

0 commit comments

Comments
 (0)