Angular Material performance problems
Tags: angular, material, performance
Published: 2021-02-25 20:25:49

---
title: Angular Material performance problems
published: true
description: Performance problems when you use material tooltip inside material scrolling
tags: Angular, Material, Performance
//cover_image: https://images.unsplash.com/photo-1597424868084-872f06020714?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1650&q=80
---

[In the last article](https://dev.to/angeloraso/angular-material-scrolling-with-multiple-columns-43e7) we created a card grid with the angular material scrolling help. Although the result was as expected, things began to get complicated. 

###Requirements:

- Minimal knowledge of angularJs and Angular is expected, including javascript and typescript.

###Sponsors:

- This article has been created thanks to [Anura]
(https://www.anura.com.ar/)'s support.

##When Things Go Wrong

Some of the texts that were shown inside the cards were too long, so we had to hide the excess text so as not to affect the design. Therefore, we add [material tooltips](https://material.angular.io/components/tooltip/overview) to all the card internal elements to communicate the hidden content to the user. However, things went wrong.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxb7o2fm19ornyxsl7ev.gif)

Suddenly, the scrolling experience was affected. When we analyzed the problem with the chrome dev tools (DevTools > More tools > Performance monitor), we found that we had 100% CPU usage. What happened? We had only added a few simple tooltips?! 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jr9g4e9nhrhbhfzwarh.gif)

The reason behind this problem was that the material tooltips have a few set of animations in their behavior and as you should know, [quoting the Google team](https://developers.google.com/web/fundamentals/design-and-ux/animations/animations-and-performance): 

> Animating properties is not free, and some properties are cheaper to animate than others. For example, animating the width and height of an element changes its geometry and may cause other elements on the page to move or change size. This process is called layout (or reflow in Gecko-based browsers like Firefox), and can be expensive if your page has a lot of elements. Whenever layout is triggered, the page or part of it will normally need to be painted, which is typically even more expensive than the layout operation itself. 

There is nothing wrong with the Angular Material Tooltips. Only that Angular was not expecting us to use them on 5 to 10 elements inside card ... inside grid of cards ... inside virtual scroll. 

One of the possible solutions would have been to cancel all the tooltip animation styles. However, because that could cause an overload in css processing work, it was preferred to create a simple tooltip without animations. 

{% stackblitz angular-material-perfonmance-problems %}

[Github repository](https://github.com/angeloraso/angular-material-performance-problems)

##Conclusion:

To avoid receiving complaints from your customers, whenever you add some changes, always remember to compare the performance before and after those changes. It's a small step for a dev, and a giant leap to become a great professional.