[Preference] How to avoid Forced Synchronous Layout or FSL to improve site preference
When tigger site updates the layout, it always follow this order:

Javascript trigger style changes, then layout changes then broswer do the paint and composite.
All those five steps should be finished in 60fps, or 16ms. Then users will have a smooth and good user experience.
For "layout", "style" and "composite", please check this site: https://csstriggers.com/
From the site, you can see that, 'transform' and 'opacity' has good preference, because they only trigger "composite", save lot of works for the broswer.



Also you can see that the method for "left", "right", they triggers all "layout", "paint", "composite"

Now let see "style" and "layout".
In general, "style" should happen before "layout", otherwise, broswer need to rerender "layout"->"style"->"layout" all over again, which is a waste for the perfermence.
To see which opreation will cause "layout" recalcuation, please checkout http://gent.ilcore.com/2011/03/how-not-to-trigger-layout-in-webkit.html, basiclly, be careful with those:
clientHeight, clientLeft, clientTop, clientWidth, focus(), getBoundingClientRect(), getClientRects(), innerText, offsetHeight, offsetLeft, offsetParent, offsetTop, offsetWidth, outerText, scrollByLines(), scrollByPages(), scrollHeight, scrollIntoView(), scrollIntoViewIfNeeded(), scrollLeft, scrollTop, scrollWidth
Let's see an example how bad it can affect our site prefermence. Example site
In this bad example, you can see taht Recalculation for "style" -> "layout" -> "style" .... "layout", it repeat number of times.

Let's see the code causes this:
function firstRun() {
divs.forEach(function(elem, index, arr) {
if (window.scrollY < 200) {
elem.style.opacity = 0.5;
}
})
}
As you can see in a forEach loop, every time you call "scollY" will cause a layout update, then we call "style.opacity" to trigger style update, but after style updated, layout will be updated again because the order, remember?

Let's see how to fix the problem:
function thirdRun() {
var newWidth = container.offsetWidth;
divs.forEach(function(elem, index, arr) {
elem.style.width = newWidth + "px";
})
}
We can simply move 'layout' update code out of forEach loop. Now the timeline looks much better!

[Preference] How to avoid Forced Synchronous Layout or FSL to improve site preference的更多相关文章
- 性能优化-FSL(Force Synchronous Layout)强制同步布局
通过chrome的Perfermance工具记录程序性能,切换到帧模式,点开其中一帧,看详情,中间为紫色的区块代表Layout,右上角带有红色三角的为警告,是chrome告知的强制同步布局,即FSL. ...
- 【译】使用requestIdleCallback
原文地址:http://galen-yip.com/2015/10/07/%E3%80%90%E8%AF%91%E3%80%91%E4%BD%BF%E7%94%A8requestIdleCallbac ...
- 提高scroll性能
在DevTools中开始渲染,向下滑动一点点滚动条,然后停止滚动. 在结果中,注意frames总是在30ftps线上面,甚至都木有很接近69ftps线的(事实上帧执行的太缓慢以致于60ftps线在图上 ...
- Should I expose synchronous wrappers for asynchronous methods?
In a previous post Should I expose asynchronous wrappers for synchronous methods?, I discussed " ...
- Preference如何增加在activity生命周期监听器
转载请注明出处:http://blog.csdn.net/droyon/article/details/41313115 本文主要介绍Preference凭什么Activit一些逻辑的生命周期,使. ...
- Android Preference详解
转载请标明出处:ttp://blog.csdn.net/sk719887916/article/details/42437253 Preference 用来管理应用程序的偏好设置和保证使用这些的每个应 ...
- Android偏好设置(7)自定义Preference,和PreferenceDialog
Building a Custom Preference The Android framework includes a variety of Preference subclasses that ...
- Android Preference使用
Android Preference经常使用在例如设置的功能,Android提供preference这个键值对的方式来处理这种情况,自动保存这些数据,并立时生效,这种就是使用android share ...
- Android中Preference的使用以及监听事件分析
在Android系统源码中,绝大多数应用程序的UI布局采用了Preference的布局结构,而不是我们平时在模拟器中构建应用程序时使用的View布局结构,例如,Setting模块中布局.当然,凡事都有 ...
随机推荐
- oc5--方法
// main.m // 第一个OC类-方法2 #import <Foundation/Foundation.h> // 1.编写类的声明 @interface Iphone : NSOb ...
- php连接符
php连接符 很多时候我们需要将几个字符串连接起来显示,在PHP中,字符串之间使用 “点” 来连接,也就是英文中的半角句号 " . " ." . " 是字符串连 ...
- Android平台下的TCP/IP传输(客户端)
在工科类项目中,嵌入式系统与软件系统或后台数据库之间的信息传输是实现“物联网”的一种必要的途径,对已简单概念的物联网,通常形式都是一个单片机/嵌入式系统实现数据的采集及其处理,通过蓝牙,wifi或者是 ...
- Kaggle爆文:一个框架解决几乎所有机器学习问题
上周一个叫 Abhishek Thakur 的数据科学家,在他的 Linkedin 发表了一篇文章 Approaching (Almost) Any Machine Learning Proble ...
- 9.18[XJOI] NOIP训练36
***在休息了周末两天(好吧其实只有半天),又一次投入了学车的怀抱,重新窝在这个熟悉的机房 今日9.18(今天以后决定不写打卡了) 日常一日总结 一个昏昏欲睡的早晨 打了一套不知道是谁出的题目,空间限 ...
- No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty planning
No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty plann ...
- Android拍照,录制视频,相机简单功能实现
1.效果图,功能没有录制出来. 基本实现了拍照,录制视频,前后摄像头切换的功能,可以转屏,聚焦. 代码在最下面,可以看代码,运行apk看实际效果. 2.权限不能忘 <uses-permissio ...
- 基于Linux/C++简单线程池的实现
我们知道Java语言对于多线程的支持十分丰富,JDK本身提供了很多性能优良的库,包括ThreadPoolExecutor和ScheduleThreadPoolExecutor等.C++11中的STL也 ...
- 杭电 2088 Box of Bricks
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2088 解题思路:一堆高度不同的砖块,需要把它们砌成一堵墙,即每一堆砖的高度相同(即砖的总数除以砖的堆数 ...
- 如何使用Matlab做数字信号处理的仿真1
例如 第三版数字信号处理P51 -1.14习题时域离散信号的相关性研究x(n)=Asin(ωn)+u(n),其中ω=π/16,u(n)是白噪声,现要求 ⑴.产生均值为0,功率P=0.1的均匀分布白噪声 ...