Chrome Performance Paint Rectangles Debug Fix
In this tutorial, you'll learn about Chrome Performance Paint Rectangles Debug Fix. We cover key concepts, practical examples, and best practices.
The Problem
Chrome DevTools Paint flashing shows green rectangles over areas being repainted. Excessive paint rectangles indicate inefficient rendering where the browser repaints more area than necessary, causing jank and high GPU usage.
Quick Fix
Step 1: Enable paint flashing in DevTools
// Wrong — guessing which elements repaint
// Right — enable paint flashing
// 1. Open Chrome DevTools (F12)
// 2. Settings (gear icon) > More Tools > Rendering
// 3. Check "Paint flashing"
// Green rectangles show areas being repainted
Step 2: Use will-change to promote layers
/* Wrong — every scroll repaints the entire element */
.animated-element {
animation: slide 0.3s ease;
}
/* Right — promote to its own layer */
.animated-element {
will-change: transform;
animation: slide 0.3s ease;
}
/* Only repaint the element, not the whole page */
Step 3: Prefer transform and opacity
// Wrong — animating layout properties causes full repaint
element.style.left = '100px'; // Triggers layout + paint
element.style.width = '200px'; // Triggers layout + paint
// Right — animating compositor-only properties
element.style.transform = 'translateX(100px)'; // Compositor only
element.style.scale = '1.5'; // Compositor only
element.style.opacity = '0.5'; // Compositor only
Step 4: Reduce paint area with containment
/* Wrong — changes inside this element repaint the whole container */
.widget {
transition: background-color 0.3s;
}
/* Right — contain repaints to the element */
.widget {
contain: paint;
transition: background-color 0.3s;
}
/* Or use content-visibility for off-screen elements */
.off-screen-section {
content-visibility: auto;
contain-intrinsic-size: 1px 500px; /* Placeholder size */
}
Step 5: Avoid repaint triggers
/* Wrong — box-shadow is expensive to paint */
.element {
box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}
/* Right — simpler shadow or use filter */
.element {
filter: drop-shadow(0 10px 20px rgba(0,0,0,0.3));
}
/* Wrong — border-radius with large areas */
.large-area {
border-radius: 20px;
background: linear-gradient(135deg, red, blue);
}
/* Right — simplify gradients and reduce border-radius on large elements */
.large-area {
background: linear-gradient(135deg, red, blue);
}
Prevention
- Keep paint rectangles small and focused — inspect with Paint flashing
- Use
will-change: transformfor animated elements - Animate only
transformandopacityfor 60fps animations - Use
contain: paintorcontent-visibility: autofor off-screen content - Avoid expensive paint properties like complex
box-shadowon large areas
Common Mistakes with paint rects
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world PERF code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro