[Performance] Optimize Paint and Composite for the website
"Paint" is one of the most preference killer, it can easily cost more than 60fps, and once you trigger "Paint" it always trigger "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 when you scrolling the page, the whole page is repainting (mark in green overlay).

Of course the whole page is re-painting is not good sign for the performance.
Record the timeline for the demo page and scroll a bit, then check the Paint Profilter:

From here you can pretty much see all the commands it runs and each step what is 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 that 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 not support will-change
DEMO site, you can see it move really slow, but if you add the css to .box, the performance improve a lot.
Notice that, only using layer promption when you are changing the position, opacity stuff, if you want to change text in the element, layer promption doesn't make any sence
Now let's say how to figure out how many layers we have in the site.
We need again our chrome devtools to help.
Select "Layout", and nav to the demo site.

Zoom in the page, until you are able to scroll the page.
Then see the dev tool:

In the layers section, you able to see how many layers you have in the page. And it tell you the reason why it is 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":
#color-block {
width: 300px;
height: 300px;
background: red;
transform: translateZ(0); // this is the key
position: relative;
z-index:;
}
And if we select "totes-promoted" block, we can see that "Composition due to association with an element overlapping other composited elements".

So be careful that when you prompt one element into a layer, the overlapping elements will be also prompted as well.
This may cause memory problem.
[Performance] Optimize Paint and Composite for the website的更多相关文章
- C++ Low level performance optimize 2
C++ Low level performance optimize 2 上一篇 文章讨论了一些底层代码的优化技巧,本文继续讨论一些相关的内容. 首先,上一篇文章讨论cache missing的重要性 ...
- C++ Low level performance optimize
C++ Low level performance optimize 1. May I have 1 bit ? 下面两段代码,哪一个占用空间更少,那个速度更快?思考10秒再继续往下看:) //v1 ...
- .net performance optimize your C# app 读书笔记
目录 序 作者简介 推荐人简介 感谢 本书简介 第一章 性能指标 第二章 性能测量 第三章 内部类型 第四章 垃圾回收机制 第五章 集合和泛型 第六章 并发和并行性 第七章 网络.I / ...
- 浏览器渲染详细过程:重绘、重排和 composite 只是冰山一角
https://juejin.im/entry/590801780ce46300617c89b8 渲染 这张很经典的图许多人都看过,其中的概念大家应该都很熟悉,也就是这么几个步骤:js修改dom结构或 ...
- Optimize Managed Code For Multi-Core Machines
Parallel Performance Optimize Managed Code For Multi-Core Machines Daan Leijen and Judd Hall This ar ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- 基于Webkit的浏览器关键渲染路径介绍
关键渲染路径概念 浏览器是如何将HTML.JS.CSS.image等资源渲染成可视化的页面的呢?本文简单介绍一下渲染过程中涉及到的关键步骤. 该过程分为四步:模型对象的构建.渲染树构建.布局.绘制. ...
- IntersectionObserver API
温馨提示:本文目前仅适用于在 Chrome 51 及以上中浏览. 2016.11.1 追加,Firefox 52 也已经实现. 2016.11.29 追加,Firefox 的人担心目前规范不够稳定,未 ...
随机推荐
- luogu3799 妖梦拼木棒
题目大意 有n根木棒,现在从中选4根,想要组成一个正三角形,问有几种选法?木棒长度都<=5000. 题解 根据容斥原理,三角形两条边分别由长度相等的单根木棒组成,另一条边由两条小于该边长的木棒构 ...
- C++字符串与指针 所有的内容也就这么多了。
1.定义一个字符串数组并初始化,然后输出其中的字符串. #include <iostream> using namespace std;int main(){ char str[]=&qu ...
- [HTML5] 新标签解释及用法
转自:http://www.cnblogs.com/yuzhongwusan/archive/2011/11/17/2252208.html HTML 5 是一个新的网络标准,目标在于取代现有的 HT ...
- WPF Menu控件自定义Style
自定义WPF中Menu控件的样式
- Nginx配置Q&A
隐藏响应头 How can remove Nginx from http response header? - Stack Overflow more_set_headers 'Server: my- ...
- Photoshop扣除特定颜色背景
步骤:打开ps--打开图片---选择--选择色彩范围---取样颜色(用吸管选定颜色)-- ( )再按delete键删除--点击文件--点击储存为PSD. 这样就抠除了特定范围色彩内的背景.
- mvc cshtml 中赋值
@{ var str = ""; str = item.ApplyStatus == ? ? ? ? "申请驳回" : ""; } < ...
- Kafka学习笔记(7)----Kafka使用Cosumer接收消息
1. 什么是KafkaConsumer? 应用程序使用KafkaConsul'le 「向Kafka 订阅主题,并从订阅的主题上接收消息.Kafka的消息读取不同于从其他消息系统读取数据,它涉及了一些独 ...
- (4.33)sql server2014内存数据库(内存中OLTP(In-Memory OLTP))
查看文章:https://blog.51cto.com/ultrasql/1626514
- java equals的用法
equals方法,用于比较两个对象是否相同,它其实就是使用两个对象的内存地址在比较.Object类中的equals方法内部使用的就是==比较运算符. package Xuexi; public cla ...