Intent to Implement and Ship: Constructible & Subclassable EventTarget

127 views
Skip to first unread message

Rakina Zata Amni

unread,
Nov 7, 2017, 4:03:28 AM11/7/17
to blin...@chromium.org

Contact emails

rak...@chromium.org


Spec

https://dom.spec.whatwg.org/#dom-eventtarget-eventtarget

Spec discussion:

- https://github.com/whatwg/dom/issues/441

- https://github.com/whatwg/dom/pull/467


Summary

Make EventTarget constructor callable, allowing them to be constructed on their own or be subclassed.


Motivation

With this change, web developers can make custom objects that benefit from EventTarget’s capability to have event listeners associated with them. Currently, to achieve EventTarget-like capability, web developers are using libraries or implementing their own event management mechanism from scratch.

Stack Overflow links related to this feature: 1, 2, 3, 4


Risks

Interoperability and Compatibility

Medium. Chrome would be the first browser to support this feature.


Edge: Public support Link

Firefox: Public support Link

Safari: No signals Link

Web developers: Positive in wanting this feature, seen on Stack Overflow links in the “Motivation” section of this email.


Interoperability tests:

- http://w3c-test.org/dom/events/EventTarget-constructible.any.html

- http://w3c-test.org/dom/events/EventTarget-constructible.any.worker.html


Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

Yes


Is this feature fully tested by web-platform-tests?

https://github.com/w3c/web-platform-tests/blob/master/dom/events/EventTarget-constructible.any.js


Link to entry on the feature dashboard

https://www.chromestatus.com/features/5721972856061952


Requesting approval to ship?

Yes


Hayato Ito

unread,
Nov 7, 2017, 5:56:41 AM11/7/17
to Rakina Zata Amni, blin...@chromium.org
Non-OWNER LGTM.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CACPC1r5hkV5h-oC%2BGK0%3Dk9rkoQ08qPw0eRhrzgP4r%2BUgW68piQ%40mail.gmail.com.

Aleks Totic

unread,
Nov 7, 2017, 1:13:56 PM11/7/17
to Hayato Ito, Rakina Zata Amni, blink-dev
I just did some performance testing of event dispatch as part of ResizeObserver release. Event dispatch was surprisingly slow. 
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/z6ienONUb5A

It would be useful to profile performance of EventTarget  vs pure Javascript EventTarget clone.

If C++ EventTarget is much slower than a JS clone, developers should know.

Aleks

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAFpjS_2u8qdcniJXpg4VdLNrBhW4aGDwH8ag3cUCXgnz1rcNXw%40mail.gmail.com.

Rakina Zata Amni

unread,
Nov 8, 2017, 3:59:46 AM11/8/17
to Aleks Totic, Hayato Ito, blink-dev
Hi Aleks,
I just did some (very simple) comparison between a pure JavaScript implementation of EventTarget from MDN (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) vs using Chrome's EventTarget. I will do more extensive comparison after this if needed, but I wonder if anyone has an opinion for this numbers. It seems like the addEventListener and dispatchEvent in Chrome is significantly slower on bigger cases.

1. Each operation done once

Pure JavaScript
  • add: 0.49072265625ms
  • dispatch: 0.946044921875ms
  • remove: 0.266845703125ms

Chrome's EventTarget
  • add: 0.138916015625ms
  • dispatch: 0.197998046875ms
  • remove: 0.07568359375ms
2. Each operation done 100x
    Pure JavaScript
    • add: 2.237060546875ms
    • dispatch: 5.389892578125ms
    • remove: 2.22802734375ms

    Chrome's EventTarget
    • add: 1.51806640625ms
    • dispatch: 7.630126953125ms
    • remove: 0.942138671875ms
    3. Each operation done 10000x

    Pure JavaScript
    • add: 132.95703125ms
    • dispatch: 272.073974609375ms
    • remove: 100.55126953125ms
    Chrome's EventTarget
    • add: 641.578857421875ms
    • dispatch: 908.40185546875ms
    • remove: 80.124755859375ms

      Dimitri Glazkov

      unread,
      Nov 8, 2017, 1:34:36 PM11/8/17
      to Rakina Zata Amni, blin...@chromium.org
      LGTM1

      Chris Harrelson

      unread,
      Nov 8, 2017, 2:00:31 PM11/8/17
      to Dimitri Glazkov, Rakina Zata Amni, blink-dev
      LGTM2

      To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.

      Daniel Bratell

      unread,
      Nov 9, 2017, 4:57:53 AM11/9/17
      to Aleks Totic, Rakina Zata Amni, Hayato Ito, blink-dev
      Seems your numbers indicate that the C++ implementation is faster than a JS implementation when it matters. I assume that your "10000x" tests have 10,000 concurrent listeners and I will bravely say that is not anything a web page would want to do.

      /Daniel
      To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
      --
      You received this message because you are subscribed to the Google Groups "blink-dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
      To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CACPC1r7rmTieFXndvJkZSGLHNMO%2BjyMT7gVsrNum%3D0tK9CZppw%40mail.gmail.com.



      --
      /* Opera Software, Linköping, Sweden: CET (UTC+1) */

      PhistucK

      unread,
      Nov 9, 2017, 5:08:21 AM11/9/17
      to Daniel Bratell, Aleks Totic, Rakina Zata Amni, Hayato Ito, blink-dev
      Has anyone compared the performance in terms of memory usage?
      Time is definitely important, but memory (and whether it is evacuated or not) is significant, too...
      While there might not be 10000x situations in a given second, there might be in a lifetime of a web application (desktop GMail and other background-persisted applications).


      PhistucK

      To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
      --
      You received this message because you are subscribed to the Google Groups "blink-dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
      --
      /* Opera Software, Linköping, Sweden: CET (UTC+1) */

      --
      You received this message because you are subscribed to the Google Groups "blink-dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
      To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/op.y9fkmgwlrbppqq%40cicero2.linkoping.osa.

      Rick Byers

      unread,
      Nov 9, 2017, 11:03:54 AM11/9/17
      to PhistucK, Daniel Bratell, Aleks Totic, Rakina Zata Amni, Hayato Ito, blink-dev
      I don't see any evidence of support from Microsoft at that link, is there discussion elsewhere?
      But it's clear Firefox supports it, and it's pretty small any so low-risk.

      LGTM3

      Rakina Zata Amni

      unread,
      Nov 9, 2017, 7:58:22 PM11/9/17
      to Rick Byers, PhistucK, Daniel Bratell, Aleks Totic, Hayato Ito, blink-dev
      I thought "On the Backlog - August 21, 2017"  in that link meant public support. Is it more appropriate to mark it as "No signals"?

      Thanks for the LGTMs! I will also try to find a way to compare the memory usage.
      Reply all
      Reply to author
      Forward
      0 new messages