Comments (2)
认领 @barretlee
from performance-column.
懒执行(Lazy Execution)
场景描述
简单来说,懒执行(Lazy Execution)就是对特定功能逻辑的初始化进行全部或部分的延迟,直到满足某一触发条件,再进行剩余部分的初始化。
懒执行的主要作用在于性能优化,再确切一点应该是首屏优化。在首屏中存在某些模块或者功能逻辑,首屏加载过程中并不会被立即使用或者使用频率非常低。为了使首屏加载性能达到最优,此时对上述这种低需或者低频的功能逻辑可以延迟进行初始化,也就是所谓的懒执行。
场景距离的含义我不是很明白,还是得请小胡子哥补充
通用方案
某一业务功能如果被设置了懒执行,则需要满足特定条件后该功能才会被初始化(唤醒)。
因此,从剩余逻辑被初始化的触发(唤醒)方式上来看,懒执行的通用方案可以大致上分为两个思路:自动唤醒和手动唤醒
-
自动唤醒
- 自动唤醒的核心**是轮询,实现方法则是依靠
setInterval()
方法。 - 首先需要定义判断条件 A,作为剩余逻辑的唤醒值。
- 其次,声明一个监听函数
monitor()
作为setInterval()
的回调函数,其基本**是根据唤醒条件 A 的满足与否来决定是否执行唤醒动作:若是则唤醒,并clearInterval
跳出轮询,否则继续轮询,直到条件满足。
从上述分析来看,自动唤醒的方案需要轮询逻辑作为支撑,本身占用一定资源。因此自动唤醒应当被用于大型逻辑模块的懒执行方案中,否则有可能在性能上会得不偿失。
- 自动唤醒的核心**是轮询,实现方法则是依靠
-
手动唤醒
手动唤醒主要应用于页面的交互场景下,也就是通过监听用户在页面内的
click
、hover
或scroll
等基本交互行为来触发唤醒动作。手动唤醒无需设置唤醒条件,也就不需要定义轮询函数来监听,完全由用户手动控制逻辑的触发,更加节省资源。因此中小型模块的懒执行方案可以选用手动唤醒方案。
from performance-column.
Related Issues (20)
- 性能优化之 PreRender HOT 3
- 性能优化之懒加载 HOT 1
- 性能优化之渐进式渲染 HOT 4
- 性能优化之数据缓存 HOT 3
- 性能优化之内联 CSS HOT 5
- 性能优化之 webp HOT 4
- 性能优化之 CDN 图片动态处理
- 性能优化之帧率 HOT 7
- 性能优化之多线程
- 性能优化之首屏白屏优化 HOT 4
- 移动端开发,你需要掌握这些内容 HOT 2
- 性能优化的几个误区 HOT 1
- 为团队打造一个性能优化闭环
- 如何排查网页的性能问题 HOT 3
- 不是性功能研究小组差评
- learn
- [归纳] JavaScript 之高性能 HOT 3
- 雅虎 35 条军规
- 性能优化之 HTTPDNS HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from performance-column.