Exploring mobile page performance and page performance
I. background:The popularity of smart terminals has changed people's habits of using the Internet, and the terminal environment has higher requirements on page performance. Next we will analyze the following figure: rendering a mobile page within 1 s
Analysis of the overall network consumption: 1. The server response should be less than 200 ms 2. There should be as few redirection as possible 3. There should be as few first-time rendering requests as possible 4. js and css congestion should be avoided.
Js execution efficiency and rendering efficiency: 1. Ms rendering time for the browser 2. Optimized js execution efficiency and rendering time
Ii. Major web Performance Optimization
Page requests: DNS Lookup, redirection reduction, parallel requests, compression, cache, on-demand loading, front-end modular running environment: interaction, animation, scrolling, memory and GC, FPS
Iii. Rendering Problems1) The performance of smart terminals and PCs varies greatly. x86 has more than 5 times the performance of ARM, and many existing performance problems have been concealed. After the Terminal Market broke out, the problem arises as follows: -There is a huge difference in the advantages and disadvantages of the terminal CPU held by the user-slow running speed-slow user operation-insufficient memory-insufficient local storage space-limited controllable resources -...
2) Why do people think iphone is better than Android in the early stage of hardware comparison between IOS and android? Smoothness: smooth animation and sliding energy saving: power saving and stability: few crash
| Operating System |
Model |
CPU |
RAM |
| Iphone |
4S |
Dual-core A5 800 MHZ |
512 M |
| Iphone |
4 |
A4 800 MHZ |
512 M |
| Iphone |
3GS |
S5PC100 600 MHZ |
256 M |
| Android |
Glaxy Note |
Exynos dual-core 1.4 GHZ |
1G |
| Android |
Nexus One |
Qualcomm 1 GHZ |
512 M |
| Android |
MOTO XT615 |
Qualcomm 800 MHZ |
512 M |
| Android |
HTC Legend |
Qualcomm 600 MHZ |
384 M |
Iv. Performance Optimization Measurement
All performance optimization is based on measurable data analysis and cannot be done to optimize unmeasurable things.
1) the number of standard frames used to determine the rendering performance:-display the average refreshing rate of the device, which is generally 50 ~ 60 HZ-1000 ms/60 = 16.6 ms (1 ms optimization means 6% Performance Improvement)
2) browser rendering engine: In FF, Layout is called reflow and Painting is called repaint.
3) frame drop in browser Rendering
4) Performance debugging tool: Timeline of the chrome debugger. Timeline has two common modes.
Events mode,
Frames (chrome-specific) mode,
TIPS: a) the shortcut key for Timeline to record behavior is ctrl + E (Mac: Cmd + E) B) the gray area is a non-rendering engine rendering behavior c) Transparent box, is the wait time in the two display refresh cycles
5) avoid repeated rendering: ensure that only two "Update rendering Tree" operations are performed at most per frame.
6) avoid repeated layout calculation: requestAnimationFrame (RAF)
A) Tips: Timeout and raf are actually working in the same thread. When the CPU is very busy, RAF execution is also blocked.
B) the differences between event behavior and RAF control are as follows: rendering a wasted rendering frame is directly triggered by event behavior, and the rendering frequency is not finally displayed by the hardware frame through RAF, combined a large number of event calculations to reduce invalid rendering times
7) page re-painting of poor DOM operations
Tip: in the source code of chromium, The updateLayoutIgnorePendingStylesheets () method is used to ignore the alternate style and recalculate the layout.
Good DOM operations
TIPS: the Dom attribute required for caching can be used for better read/write splitting.
7) avoid repeated rendering behaviors. a) Use RAF to control the animation within a reasonable refresh time. B) ensure atomic operations of the rendering engine and perform read/write separation in batches using dom. c) different styles have different manifestations in the rendering mode, such
5. smooth animation
1) DOM animation's four major artifacts shift: transform: translate (npx, npx); ZOOM: transform: scale (n); rotate: transform: rotate (ndeg); Transparent: opacity: 0 ~ 1;
Vi. Interactive Animation Optimization
1) GPU acceleration (Composite): How does a GPU work in a browser? In high-end browsers (webkit, chrome), the Painting behavior is that the CPU prepares Texture Materials for the GPU.
Tip: You can enable show composited layer borders in the chrome debugger to view Image Texture Materials.
2) Available GPU advantages: texture cache and graphics layer GPU Hack: a),-webkit-transform: translate3D (0px, 0px, 0px); // create Layout, and move layers in the GPU. B) force the dom object to be animated to create Layout cache-webkit-transform: translateZ (0); // create Layout and cache in the GPU. -Webkit-backfface-visibility: hidden; common attributes include: translateZ, Perspective, backface-visibility, scaleZ, RotateZ, RotateX, RotateY, Translate3D, Scale3D, and Rotate3D.
3) Reasonable Use of GPU to accelerate a) GPU acceleration actually utilizes the cache on the GPU layer to allow reuse of rendering resources. B) GPU acceleration is a double-edged sword. Too many GPU layers will also bring performance overhead. Please note whether the Composite Layouts exceeds 16 ms. C) Create a GPU layer only for user behavior and animation scenarios, but reclaim it in time.
4) some notes for css3 animation a) the use of translate2D alone does not generate a GPU layer and does not synthesize in the GPU. B) CSS complementing animation works with translate2D to generate a temporary layer in the GPU for computation. However, changes to layout calculation are ineffective. C) CSS3 animation is usually not blocked. You can obtain independent threads for rendering.
TIPS: 1. If you need to avoid rendering tree computing completely, consider Canvas2. Use classList instead of className. However, in chrome33 dev, the common "className =" can already be determined by the same name, to reduce repeated style rendering.