Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devtools warning - forced reflow is a likely performance bottleneck - morris.js

I have a page wherein I am displaying 23 donut charts using morris.js plugin. During performance analysis I came across this: enter image description here

Of course there are 22 more of these warnings. The resultant time is 401ms.
My implementation of each donut chart is as follows:

Morris.Donut({
                    element: 'element1',
                    resize: false,
                    data: [{
                            label: "temp1",
                            value: temp1Value
                        },
                        {
                            label: "temp2",
                            value: temp2Value
                        },
                        {
                            label: "temp3",
                            value: temp3Value
                        }

                    ],
                    colors: ["#46BFBD", "#993366", "#993366"]
                });

I read in some posts that I should separate reads from writes. Any pointers how to implement this? Considering all 23 charts?

like image 822
theusual Avatar asked May 03 '17 23:05

theusual


1 Answers

The comments to the question sum it up pretty well but I'll just document this more comprehensively and generally for anyone else that stumbles on this

Forced synchronous layouts AKA forced reflows occur when a page sets a CSS property that affects the layout of the element, and then some JS queries the layout position of the element. Since the layout position may have changed, the browser needs to re-compute the position.

You can check what properties cause layout at https://csstriggers.com/

If it happens to be your code that's causing the layout, then you want to refactor it to avoid setting layout then querying position

But it's likely not your code that's causing the forced synchronous layout. Under Recalculation Forced you can see the line of code that causes the FSL. Clicking the link takes you to that line of code.

You can learn the basics of diagnosing FSL using DevTools in Get Started With Analyzing Runtime Performance

And you can learn more about the theory of FSL in Avoid Forced Synchronous Layouts

like image 180
Kayce Basques Avatar answered Nov 09 '22 12:11

Kayce Basques