You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is this really necessary? @stefanpenner suggested that we might instead have components opt-in to needing this, instead of assuming we need a run loop on mouse movement.
It's only happening just in-case someone has a mouse related handler on one of the rendered components. If instead components informed the event dispatcher the events they need on render and no longer need on un render. We could remove this, instead only listening to exactly what is required.
The mouse/touch events introduce an unfortunate cost, especially when they are not frequently used.
@chadhietala - In that scenario, you are not actually using the EventDispatcher (or Ember event bubbling at all), you are registering a custom onmouseover handler.
@chadhietala - No, {{action "foo" on="mouseover"}} would definitely go through EventDispatcher, and would have the issue you are cautioning against if we didn't take it into account.
Yup it causes a run loop, but it's one that you want. Since you are absolutely invoking ember code. This is much better then all the preemptive handlers that run for. All mouse events regardless of if a handler is present.
An interim step is actually to skip the run loop for events that don't find a handler.
To handle bubbling correctly, it may need to be slightly more creative.
This approach I believe will be the easiest, no ref counting needed. Sure we sill need to attach event listeners to everything, but we only bother invoking a run-loop if we truely are about to invoke code that requires it.
I suspect this will cure the original concern which prompted this issue.
So to make sure I understand this, the idea is to:
Check the immediate view to see if actually has a handler for the given event
If handler present, proceed
If not, repeat on parent, if no parent, no-op
This sounds like it will address my issue. However, what is more expensive, traversing the view hierarchy looking for handlers, or executing a no-op run loop?
The mouse/touch events introduce an unfortunate cost, especially when they are not frequently used.
jQuery fast paths event handling for many events, I think Ember should likely look into doing so too, in addition to any inquiry into using useCapture for events. Therese a huge perf win being able to delegate directly instead of bubbling, and the current implementation not only needs to bubble, but needs to run multiple checks at each view/component layer for handlers.
I'd put the overall cost on this as an extra .5-4ms / touchmove or mousemove event that's being used to manipulate position on screen (much of which depends on how many layers it needs to bubble through etc.). Not horrendous, but definitely expensive when lots of such events are involved.
(Edit: that cost I peg above is a rough eyeball of the difference between using touchmove through Ember and using it as a direct handler on the component)
PR coming as soon as I finish off the walker. Will also be adding a second flag for resolution caching (e.g. from element to handler) so that repeated firing is super fast.
Activity
stefanpenner commentedon Jun 23, 2015
It's only happening just in-case someone has a mouse related handler on one of the rendered components. If instead components informed the event dispatcher the events they need on render and no longer need on un render. We could remove this, instead only listening to exactly what is required.
The mouse/touch events introduce an unfortunate cost, especially when they are not frequently used.
asakusuma commentedon Jun 24, 2015
Is there a way to infer this from the component, or would the component need to manually declare what is needs?
If the latter, we'd need to choose the set of events that are listened for by default, and the set of events you need to manually opt in to.
stefanpenner commentedon Jun 24, 2015
yes, https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/views/component.js#L223 is how one declares interest in an event from a component.
asakusuma commentedon Jun 24, 2015
So then we could just ref count this on component creation and the decrement on destruction, and then add and remove this listener as needed?
chadhietala commentedon Jun 24, 2015
I think this gets tricky with improved actions, because you can declare event handlers in the template.
You completely loose the ability to introspect the class.
rwjblue commentedon Jun 24, 2015
@chadhietala - In that scenario, you are not actually using the
EventDispatcher(or Ember event bubbling at all), you are registering a customonmouseoverhandler.chadhietala commentedon Jun 24, 2015
@rwjblue So it doesn't cause a runloop? Is this the same for the old
on=syntax as well?rwjblue commentedon Jun 24, 2015
@chadhietala - No,
{{action "foo" on="mouseover"}}would definitely go throughEventDispatcher, and would have the issue you are cautioning against if we didn't take it into account.stefanpenner commentedon Jun 24, 2015
Yup it causes a run loop, but it's one that you want. Since you are absolutely invoking ember code. This is much better then all the preemptive handlers that run for. All mouse events regardless of if a handler is present.
An interim step is actually to skip the run loop for events that don't find a handler.
stefanpenner commentedon Jun 24, 2015
https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/system/event_dispatcher.js#L234-L242 could likely detect if the given view has such a handler, and only invoke the run-loop if it is about to enter user code.
To handle bubbling correctly, it may need to be slightly more creative.
This approach I believe will be the easiest, no ref counting needed. Sure we sill need to attach event listeners to everything, but we only bother invoking a run-loop if we truely are about to invoke code that requires it.
I suspect this will cure the original concern which prompted this issue.
asakusuma commentedon Jun 24, 2015
So to make sure I understand this, the idea is to:
This sounds like it will address my issue. However, what is more expensive, traversing the view hierarchy looking for handlers, or executing a no-op run loop?
stefanpenner commentedon Jun 24, 2015
We traverse it anyways
runspired commentedon Jun 24, 2015
jQuery fast paths event handling for many events, I think Ember should likely look into doing so too, in addition to any inquiry into using
useCapturefor events. Therese a huge perf win being able to delegate directly instead of bubbling, and the current implementation not only needs to bubble, but needs to run multiple checks at each view/component layer for handlers.I'd put the overall cost on this as an extra .5-4ms / touchmove or mousemove event that's being used to manipulate position on screen (much of which depends on how many layers it needs to bubble through etc.). Not horrendous, but definitely expensive when lots of such events are involved.
(Edit: that cost I peg above is a rough eyeball of the difference between using touchmove through Ember and using it as a direct handler on the component)
stefanpenner commentedon Jun 24, 2015
I believe we are limited by our ie9 support and a true bubbling phase. Maybe not?
Would love for someone to dive into this area an propose some improvements. Enumerating cost/benefit would also be handy
runspired commentedon Jun 24, 2015
IE9 allows for
useCapture, IE8 support doesn't.20 remaining items
runspired commentedon Aug 11, 2015
I did some perf testing on
useCaptureusing a mechanism that would allow us to maintain ember's current eventing mechanics for the moment without changing any expected behavior: http://jsperf.com/event-delegation-with-capture-vs-bubbleTL;DR ~45% performance boost across the board.
stefanpenner commentedon Aug 13, 2015
@rwjblue closed in favor of rfc/implementation?
runspired commentedon Aug 13, 2015
your commit doesn't fix the run loop join, only the ability to turn mousemove off
runspired commentedon Aug 13, 2015
^@rwjblue
stefanpenner commentedon Aug 13, 2015
Maybe we need to bundle up some of the talking points and push some work for capture phase + improved event dispatcher.
Having vague hard to action issues is annoying.
runspired commentedon Aug 13, 2015
@stefanpenner I have a branch where I am working on this actually, I think it's been added to your Friday schedule as a talking point
stefanpenner commentedon Aug 13, 2015
Awesome. Can you link it. Or submit a WIP for review?
runspired commentedon Aug 13, 2015
PR coming as soon as I finish off the walker. Will also be adding a second flag for resolution caching (e.g. from element to handler) so that repeated firing is super fast.
https://github.com/runspired/ember.js/commit/f682df07fbb6ba92d13ee618b19f764bf85262f9
rwjblue commentedon Aug 13, 2015
@stefanpenner - It is also on our agenda for Friday.
rwjblue commentedon Aug 13, 2015
Sorry I was trying to reference this issue, not close it.
Merge pull request #12075 from runspired/event-runloop-fix
dont spin up extra run-loops when bubbling events. Fixes #11540