material icon indicating copy to clipboard operation
material copied to clipboard

(perf) md-tooltip triggers digest cycles on scroll

Open skosno opened this issue 10 years ago • 3 comments

In the latest (1.0.1) it seems that md-tooltip is very greedy about scroll event - basically any scroll on page is triggering digest cycle (no throttling etc. = a lot of digests!). At the moment we disabled tooltips because of that but in my opinion this needs to be addressed.

Here is a very simple codepen based on md-tooltip demo page. http://codepen.io/anon/pen/rxyJaZ

I added small vanilla JS counter that is triggered whenever my watcher function is triggered. You can see that any scroll on the page creates whole lot of digests. It does seem that tooltip is using runs "setVisible(false)" https://github.com/angular/material/blob/master/src/components/tooltip/tooltip.js#L150

And it uses "$mdUtil.nextTick" to set "scope.visible = false;" so that it coalesces calls. Unfortunately it seems it is not enough for desktop browser scroll (this is tested on OSX) and processQueue is called multiple times per scroll. Maybe some kind of debounced function as windowScroll would be better here?

skosno avatar Jan 06 '16 13:01 skosno

BTW. maybe check if tooltip is currently visible/hidden and not trigger digest at all when setVisible is called with same value as current?

like https://github.com/angular/material/blob/master/src/components/tooltip/tooltip.js#L190 :

if(scope.visible === !!value) {
  return;
}

?

skosno avatar Jan 06 '16 13:01 skosno

We need additional check if the value is queued.

if ((setVisible.queued && setVisible.visible === !!value) || (!setVisible.queued && scope.visible === !!value)) {
  return;
}

interstella-5555 avatar Jan 06 '16 13:01 interstella-5555

closed with 65239b7

EladBezalel avatar Apr 18 '16 14:04 EladBezalel