Slide 1

Slide 1 text

Layout Repaint & The Lessons Learned Irfan Maulana Principal Engineer Web Platform, Tokopedia Semarang

Slide 2

Slide 2 text

mazipan.space

Slide 3

Slide 3 text

Loading Performance Lighthouse CLS LCP Speed Index TTI TTFB

Slide 4

Slide 4 text

Runtime Performance DevTools FPS CPU Usage Main Thread GC

Slide 5

Slide 5 text

Pixel Pipeline

Slide 6

Slide 6 text

Visual Change Trigger (JS/CSS) Common pixel pipeline Style Calculation Layout Paint Composite

Slide 7

Slide 7 text

How to debug?

Slide 8

Slide 8 text

Paint Flashing On Chrome DevTools

Slide 9

Slide 9 text

Timeline on Safari

Slide 10

Slide 10 text

Recommendation

Slide 11

Slide 11 text

Recommendations 1. Optimize JavaScript Execution 2. Reduce the Scope and Complexity of Style Calculations 3. Avoid Large, Complex Layouts and Layout Thrashing 4. Simplify Paint Complexity and Reduce Paint Areas 5. Stick to Compositor-Only Properties and Manage Layer Count 6. Debounce Your Input Handlers

Slide 12

Slide 12 text

Lesson Learned

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Unnecessary Rendering See: https://codesandbox.io/s/aloha-css-uyox7 Problems: - Box repainting on sliding - Hello3 & Hello4 unnecessary repaint Hints: - Stacking context - will-change

Slide 15

Slide 15 text

Infinite hidden animation See: https://codepen.io/mazipan/details/gOGLpev Problems: - Skeleton loading for hidden element triggering repaint Alternatives: - Remove skeleton loading, or - Only show before the element will showing

Slide 16

Slide 16 text

JS First Problems: - Countdown timer w JS approach will always trigger repaint for every second Alternatives: - Use CSS/SVG transition w JS for only generating the initial state

Slide 17

Slide 17 text

50% * Reduce more than CPU usage *On idle state

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

ksana.in/learn-render-perf

Slide 20

Slide 20 text

ksana.in/udacity-render-perf

Slide 21

Slide 21 text

Key Takeaways 1. Stick to the compositor-only props 2. Double check your Stacking Layer 3. Check the hidden element 4. CSS First 5. Measure periodically

Slide 22

Slide 22 text

Thank You.