[Performance] Optimize Paint and Composite for the website

Source: Internet
Author: User
Tags chrome devtools

"Paint" is one of the most preference killer, it can easily cost more than 60fps, and once your trigger "Paint" it always t Rigger "Composite" as well.

First of all, let's see how to use Chrome devtools to help us identifiy the Paint problem.

A. Turn on rendering:

Then check the "Paint flasing" option.

Then use this demo site, keep "Paint flashing" open, and you should see if you scrolling the page, the whole page is re Painting (mark in green overlay).

Of course the whole page is re-painting are not good sign for the performance.

Record the timeline for the demo page and scroll a bit, then check the Paint profilter:

From this can pretty much see all the commands it runs and each step what's painted to the page.

Composite:

To avoid too much painting, we can put different compoment in different layouts.

For example the Side-nav compoment, to prevent the whole page re-paint again and again, we can put side nav in a different Layout, so, the main page won ' t re-paint.

Prompt element into a layout:

Code That works:

Will-change:transform;transform:translatez (0); Hack for some browser no support Will-change

DEMO site, you can see it move really slow and if you add the CSS to. box, the performance improve a lot.

Notice that, only using a layer promption when is changing the position, opacity stuff, if you want to change text in T He element, layer promption doesn ' t make any sence

Now let's say how to figure out how many layers we had in the site.

We need again our chrome devtools-to-help.

Select "Layout", and Nav to the demo site.

Zoom in the page, until is able to scroll the page.

Then see the Dev Tool:

In the layers sections, you able to see how many layers the page. And it's the reason why it's a composition layer, in the image, it says that "composition due to association with An element with a CSS 3D transform ".

If you check the CSS code for "#color-block":

{    width: 300px;     height: 300px;     background: Red;     transform: translatez (0); //This is the key    position: relative;     z-index: 0;}

And if we select "totes-promoted" block, we can see the "Composition due to association with an element overlapping< /c19> other composited elements ".

So is careful that when you prompt one element into a layer, the overlapping elements would be also prompted as well.

This may cause memory problem.

[Performance] Optimize Paint and Composite for the website

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.