[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模块中布局.当然,凡事都有 ...
随机推荐
- Powershell 渗透测试工具-Nishang
Powershell 渗透测试工具-Nishang 分享到: 作者:V1ct0r 稿费:500RMB(不服你也来投稿啊!) 投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿 传送门 ...
- 循环神经网络(RNN, Recurrent Neural Networks)——无非引入了环,解决时间序列问题
摘自:http://blog.csdn.net/heyongluoyao8/article/details/48636251 不同于传统的FNNs(Feed-forward Neural Networ ...
- DDos攻击篇
DDoS(Distributed Denial of Service,分布式拒绝服务)攻击的主要目的是让指定目标无法提供正常服务,甚至从互联网上消失,是目前最强大.最难防御的攻击之一. 1.1. SY ...
- java javax.annotation.Resource注解的详解
转自:https://www.jb51.net/article/95456.htm java 注解:java javax.annotation.Resource 当我们在xml里面为类配置注入对象时 ...
- java exception 异常错误记录
//异常:Could not obtain transaction-synchronized Session for current thread 做定时器的时候用ApplicationContext ...
- 自定义typecho后台路径
如何自定义后台路径 Typecho 安装好后,默认的后台路径是 domain.com/admin/,为了提高安全性,我们允许以 domain.com/xxxx/ 的方式访问,其中 xxxx 是你自定义 ...
- 4185 Oil Skimming 最大匹配 奇偶建图
题目大意: 统计相邻(上下左右)的‘#’的对数. 解法: 与题目hdu1507 Uncle Tom's Inherited Land*类似,需要用奇偶建图.就是行+列为奇数的作为X集合,偶尔作为Y集合 ...
- Django学习笔记----settings and database_based App demo
原文参考docs.djangoproject.com, what can manage.py utility do? find here. 1.Database Setup 编辑settings.py ...
- DELPHI调试出现disconnected session的解决办法
我在控制面板中,是禁用了UAC的,如下图 但是,在注册表中启用了UAC(EnableLUA), 工程中请求了管理员权限,如下图: 所以,整个权限请求混乱了. 解决办法,要么把注册表的LUA设置为0,要 ...
- Redis 四:存储类型之散列类型
1.散列类型表达方式简介: =========================================== 键 字段 值 =================================== ...