components icon indicating copy to clipboard operation
components copied to clipboard

[Tooltip] Rendering many tooltips is slow

Open alexsapps opened this issue 9 years ago • 14 comments

Hello, I just wanted to report that using mdTooltip too much seems to slow down rendering time of my Angular app by a lot compared to adding many other components or *ngIfs.

I had a table that make s in an *ngFor and had 3 tooltips per row, and each row had a component tree with 15 ngIfs (transitively) and the component subtrees were of size ~10, but those 3 mdTooltips accounted for half of the change detection rendering time. (Removing the tooltip reduced rendering time in half. Computation of the tooltip text was trivial.)

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

At least Chrome

alexsapps avatar Jun 27 '17 02:06 alexsapps

Can you provide a plunker example?

julianobrasil avatar Jun 27 '17 19:06 julianobrasil

Here's a plunker, but in the plunker it's fast. Yet in my project, I double checked again simply adding an mdTooltip="0" attribute is slowing it way down. I can't tell if the plunker is using the latest Angular / Material code. Is there an up-to-date starter plunker with Angular Material already set up?

https://plnkr.co/edit/HtEUoZ28ti3xILgxpyFJ?p=info

alexsapps avatar Jun 28 '17 03:06 alexsapps

Ok, updated the plunker, please see previous message. (I made a mistake and timed the same thing twice.)

In my browser, 1000 ngIfs renders in 50-90ms, whereas 1000 mdTooltips renders in 390-450ms.

alexsapps avatar Jun 28 '17 03:06 alexsapps

I see it... but I don't think it's so unexpected. Not sure, but suposing the mdTooltip is based on mousein and mouseout events, it has to register them. Registering an event is a considerable time consuming task (and you're doing it a lot in the plunker).

To see the if component rendering time increase two times the actual value in your plunker, just register a click event in the <span>: (click)="compute(2)". Over here, it jumps from 63ms to 140ms just because of this. With two event handlers, it jumps to 225ms.

But I think the material guys will give you a more accurate answer. I don't know if it could be possible to do something like a lazy event registering (immediatly after the component is rendered). It would give the final user a better experience.

julianobrasil avatar Jun 28 '17 05:06 julianobrasil

I heard Angular is now using native addEventListner for better performance.

However now it seems even slower, taking over 600ms to render 1000 tooltips, and each time I click it goes slower and slower.

Updated plunker since the old one stopped working: https://plnkr.co/edit/q3w43vEFOQukzWuuRGJb?p=preview

alexsapps avatar Aug 10 '17 19:08 alexsapps

Just encountered this issue while adding matTooltips to large arrays of data

Here is a simplified version in a stackblitz, it will initially load a little slow but not too bad, uncommenting lines 14 and 17 in app.component.ts will make it significantly slower:

https://stackblitz.com/edit/angular-4x8ama?file=app%2Fapp.component.ts

ztgluis avatar Nov 07 '17 22:11 ztgluis

I get this lag too. If on of my function (even parent) have a console.log I see it's output on EVERY mosemove on tooltip of any (even child) components

SaturnTeam avatar Feb 14 '18 01:02 SaturnTeam

I get this too. Say I have 20 blocks, which has header block which contains 2 div with tooltips (each div).

When I reduced to 1 for each header block, the performance noticeably improved...

tuanjinn avatar Jul 25 '18 15:07 tuanjinn

same here... We cannot use mat-tooltips...

nickwinger avatar Aug 29 '18 10:08 nickwinger

Hello,

I know the issue is old, but I'm having the same issue with Angular Material ^8.0.0.

The guys in my team found a work around by using SVG : create ONE custom tooltip and moving it on the hovered element (with a mess of absolute x and y calculation).

CNicolas avatar Jun 06 '19 14:06 CNicolas

@CNicolas, you can try https://github.com/ncstate-sat/popover. It's very flexible, based on cdkOverlay and you can have just one instance (and anchors all over de place).

julianobrasil avatar Jun 06 '19 14:06 julianobrasil

Thank you @julianobrasil, it worked perfectly !

CNicolas avatar Jun 21 '19 06:06 CNicolas

There have been a handful of perf improvements for tooltips since this was opened: https://github.com/angular/components/pulls?q=is%3Apr+tooltip+is%3Aclosed+perf

Going to close, but feel free to open a new issue if anyone has an example of excessive perf cost.

jelbourn avatar Apr 02 '21 19:04 jelbourn

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.