Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Intent to implement and ship: "passive" option for AddEventListenerOptions

73 views
Skip to first unread message

Kartikaya Gupta

unread,
May 5, 2016, 10:08:15 AM5/5/16
to dev-platform, Rick Byers
Summary: Authors can declare in their addEventListener call that the
listener will not be calling preventDefault() on the event. This
unlocks certain performance optimizations.

Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1266066

Link to standard:
https://dom.spec.whatwg.org/#dom-addeventlisteneroptions-passive -
note that this intent email is specifically about the "passive" flag;
the AddEventListenerOptions dictionary and addEventListener
modifications were already implemented in bug 1266194. I don't recall
seeing an intent email for that but maybe I missed it.
There is also an explainer doc at
https://github.com/WICG/EventListenerOptions which might be easier to
read for those already familiar with DOM events.

Platform coverage: all platforms

Estimated or target release: Hoping to get it in Firefox 49. I wrote
the patches today (they were pretty small) hence combining the intent
to implement and ship into this email rather than sending two separate
emails.

Preference behind which this will be implemented: none at the moment

Other browsers: See
https://github.com/WICG/EventListenerOptions#status-of-implementations

Justin Dolske

unread,
May 5, 2016, 3:21:15 PM5/5/16
to Kartikaya Gupta, dev-platform, Rick Byers
How will a developer know when it would be worthwhile to mark their event
listener as passive? Do we perhaps log something to the console?

Justin
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>

Kartikaya Gupta

unread,
May 5, 2016, 4:20:55 PM5/5/16
to Justin Dolske, dev-platform, Rick Byers
In general developers should probably default to marking their
listeners as passive, unless their listeners are actually going to
call preventDefault(). We don't have a console log for saying "use a
passive listener", no. We can easily detect listeners that are not
marked passive and that are impacting scrolling latency (for example),
but it's impossible to tell with 100% accuracy if those listeners
*should* be marked passive or not. Some of those listeners are
probably legitimately not passive, because they do call
preventDefault() under some conditions - but we can't know that until
those conditions occur and preventDefault() is called.

Cheers,
kats

Markus Stange

unread,
May 5, 2016, 6:57:51 PM5/5/16
to
On 2016-05-05 3:21 PM, Justin Dolske wrote:
> How will a developer know when it would be worthwhile to mark their event
> listener as passive? Do we perhaps log something to the console?

The Chrome devtools have two features to help with this: They have a
checkbox for "Show scrolling perf issues" which draws annotated
rectangles over those areas of the page that have non-passive wheel
event listeners, and their event listener list explicitly marks
non-passive event listeners with "passive: false". We could do something
similar.

Both of these features are demonstrated in a screen cast Rick Byers
uploaded at https://www.youtube.com/watch?v=6-D_3yx_KVI .

-Markus

Eric Shepherd

unread,
May 5, 2016, 10:43:21 PM5/5/16
to Kartikaya Gupta, dev-platform, Rick Byers
What happens if the developer specifies passive yet calls
preventDefault() anyway?

------------------------------------------------------------------------
*From:* Kartikaya Gupta
*Sent:* Wednesday, May 4, 2016 6:19:20 PM EDT
*To:* dev-platform
*Cc:* Rick Byers
*Subject:* Intent to implement and ship: "passive" option for
AddEventListenerOptions

> Summary: Authors can declare in their addEventListener call that the
> listener will not be calling preventDefault() on the event. This
> unlocks certain performance optimizations.

--

Eric Shepherd
Senior Technical Writer
Mozilla Developer Network <https://developer.mozilla.org/>
Blog: https://www.bitstampede.com/
Twitter: http://twitter.com/sheppy
Doodle: http://doodle.com/the.sheppy

Anne van Kesteren

unread,
May 6, 2016, 1:01:47 AM5/6/16
to Eric Shepherd, dev-platform, Rick Byers, Kartikaya Gupta
On Fri, May 6, 2016 at 4:43 AM, Eric Shepherd <eshe...@mozilla.com> wrote:
> What happens if the developer specifies passive yet calls
> preventDefault() anyway?

That's a no-op per https://dom.spec.whatwg.org/#dom-event-preventdefault.


--
https://annevankesteren.nl/

Kartikaya Gupta

unread,
May 6, 2016, 10:11:13 AM5/6/16
to Anne van Kesteren, dev-platform, Eric Shepherd, Rick Byers
Correct, the preventDefault() is ignored from a passive listener, and
we will probably log a warning to the console (I have a patch up for
review that does that, let's see what smaug says).

Eric Shepherd

unread,
May 6, 2016, 11:36:38 AM5/6/16
to Anne van Kesteren, dev-platform, Rick Byers, Kartikaya Gupta
That's what I figured, but the articles about it didn't seem to say, and
the late hour caused me not to think to look at the spec itself. Good deal.
0 new messages