-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
worker: make MessagePort inherit from EventTarget #34057
Conversation
364897d
to
50a3cea
Compare
And here comes the big yikes…
I assume this will require some more work to get into an acceptable range. 😕 |
Sigh... yeah, unfortunately I think that's expected. |
So … moving Here’s the benchmark results after those modifications:
still not great, but probably this would already be in the acceptable range for me. |
hmm... that's definitely better but still really slow. Let's do some more profiling and see if we can it down further before moving forward. |
This test has not been working correctly since at least a555be2. Since it tests internals, any replacement test might become invalid in a similar way.
Enable `NodeEventTarget` as a base class for `MessagePort`, by enabling special processing of events for Node.js listeners, and removing implicit constructors/private properties so that classes can be made subclasses of `NodeEventTarget` after they are created.
The messaging code uses `Object.defineProperty()`, which accesses `value` on `Object.prototype` by default, so some calls to the getter here would actually be expected. Instead, make the list of accessed properties more specific to the tested source map code to avoid flakiness. Refs: https://twitter.com/addaleax/status/1276289101671608320
Use `NodeEventTarget` to provide a mixed `EventEmitter`/`EventTarget` API interface.
9b73f8d
to
6b1926f
Compare
This test has not been working correctly since at least a555be2. Since it tests internals, any replacement test might become invalid in a similar way. Refs: nodejs#34057
The messaging code uses `Object.defineProperty()`, which accesses `value` on `Object.prototype` by default, so some calls to the getter here would actually be expected. Instead, make the list of accessed properties more specific to the tested source map code to avoid flakiness. Refs: https://twitter.com/addaleax/status/1276289101671608320 Refs: nodejs#34057
The more I try to work on lessening the performance impact here, the more I become convinced that the current approach behind So, I think it makes sense to take a different approach to |
The |
Fwiw, I don’t see any strict technical limitation that prevents us from achieving performance parity in the case that only Node.js-EventEmitter-style usage is taking place. |
Okay, I’ve switched to another approach – instead of lazily generating the Node.js
The bottom two are using EventTarget-style listeners, the top two are using EventEmitter-style listeners. I’m personally okay with this, particularly since we’re considering this semver-major anyway. This does not include the optimization from #34459 yet, so numbers will likely be better than this in practice (and will improve along with our @jasnell @devnexen @benjamingr @Ethan-Arrowood Could you take another look? |
Use `NodeEventTarget` to provide a mixed `EventEmitter`/`EventTarget` API interface. PR-URL: #34057 Refs: https://twitter.com/addaleax/status/1276289101671608320 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 doc: * add AshCripps to collaborators (AshCripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 events: * (SEMVER-MINOR) expand NodeEventTarget functionality (Anna Henningsen) #34057 src: * (SEMVER-MINOR) allow preventing SetPromiseRejectCallback (Shelley Vohr) #34387 * (SEMVER-MINOR) allow setting a dir for all diagnostic output (AshCripps) #33584 worker: * (SEMVER-MINOR) make MessagePort inherit from EventTarget (Anna Henningsen) #34057 zlib: * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: #34542
Use `NodeEventTarget` to provide a mixed `EventEmitter`/`EventTarget` API interface. PR-URL: #34057 Refs: https://twitter.com/addaleax/status/1276289101671608320 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: deps: * upgrade npm to 6.14.7 (claudiahdz) #34468 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 doc: * add AshCripps to collaborators (AshCripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 events: * (SEMVER-MINOR) expand NodeEventTarget functionality (Anna Henningsen) #34057 src: * (SEMVER-MINOR) allow preventing SetPromiseRejectCallback (Shelley Vohr) #34387 * (SEMVER-MINOR) allow setting a dir for all diagnostic output (AshCripps) #33584 worker: * (SEMVER-MINOR) make MessagePort inherit from EventTarget (Anna Henningsen) #34057 zlib: * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: #34542
Notable changes: deps: * upgrade npm to 6.14.7 (claudiahdz) #34468 dgram: * (SEMVER-MINOR) add IPv6 scope id suffix to received udp6 dgrams (Pekka Nikander) #14500 doc: * add AshCripps to collaborators (AshCripps) #34494 * add HarshithaKP to collaborators (Harshitha K P) #34417 * add rexagod to collaborators (Pranshu Srivastava) #34457 * add release key for Richard Lau (Richard Lau) #34397 events: * (SEMVER-MINOR) expand NodeEventTarget functionality (Anna Henningsen) #34057 src: * (SEMVER-MINOR) allow preventing SetPromiseRejectCallback (Shelley Vohr) #34387 * (SEMVER-MINOR) allow setting a dir for all diagnostic output (AshCripps) #33584 worker: * (SEMVER-MINOR) make MessagePort inherit from EventTarget (Anna Henningsen) #34057 zlib: * switch to lazy init for zlib streams (Andrey Pechkurov) #34048 PR-URL: #34542
The messaging code uses `Object.defineProperty()`, which accesses `value` on `Object.prototype` by default, so some calls to the getter here would actually be expected. Instead, make the list of accessed properties more specific to the tested source map code to avoid flakiness. Refs: https://twitter.com/addaleax/status/1276289101671608320 Refs: #34057 PR-URL: #34446 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
The messaging code uses `Object.defineProperty()`, which accesses `value` on `Object.prototype` by default, so some calls to the getter here would actually be expected. Instead, make the list of accessed properties more specific to the tested source map code to avoid flakiness. Refs: https://twitter.com/addaleax/status/1276289101671608320 Refs: #34057 PR-URL: #34446 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
stopMessagePort(this); | ||
} | ||
class MessageEvent extends Event { | ||
constructor(data, target, type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax any reason target
is passed here but not stored as in lib/internal/per_context/messageport.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GeorgeSapkin That’s because, for Event
s, the target
property is set when they are being emitted. It’s a slight incompatibility between the main-context and non-main-context behaviors, but I doubt that it matters so long as you can access event.target
inside of a message event handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if it's not being used there's no point passing it, i.e. the target
argument can be removed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the only reason for the parameter being here is for alignment with the class in lib/internal/per_context/messageport.js, but I think it could be removed here.
events: fix add-remove-add case in EventTarget
Make sure that listeners are added properly if there has previously
been one but currently are none for a given event type.
(→ #34056)
test: delete invalid test
This test has not been working correctly since at least a555be2.
Since it tests internals, any replacement test might become invalid
in a similar way.
events: expand NodeEventTarget functionality
Enable
NodeEventTarget
as a base class forMessagePort
,by enabling special processing of events for Node.js listeners,
and removing implicit constructors/private properties so that
classes can be made subclasses of
NodeEventTarget
after theyare created.
test: fixup worker + source map test
The messaging code uses
Object.defineProperty()
, which accessesvalue
onObject.prototype
by default, so some calls to thegetter here would actually be expected. Instead, make the list
of accessed properties more specific to the tested source map
code to avoid flakiness.
Refs: https://twitter.com/addaleax/status/1276289101671608320
worker: make MessagePort inherit from EventTarget
Use
NodeEventTarget
to provide a mixedEventEmitter
/EventTarget
API interface.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes