Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
07

Frontend System Design · Lesson 7 of 86 · 4 min

Layout, Paint and Compositing

This is how you explain why one animation is janky and another is smooth, and prove you can write performant UI code.

After the browser builds the render tree, it has to turn that tree into pixels on the screen. This happens in a sequence called the rendering pipeline. Understanding this sequence is non-negotiable for diagnosing and fixing UI performance issues.

The pipeline has three main stages that your code can affect: Layout, Paint, and Compositing. The goal is to do as little work as possible. The cheapest updates only involve Compositing. The most expensive ones start all the way back at Layout.

The pipeline: from CSS change to pixels

When you change a style, the browser has to figure out which of these stages to run. It does the minimum work required.

  • Layout: The browser calculates the geometry of elements. Where are they on the page? How big are their boxes? A change to one element's width can affect everything after it, so this stage can be expensive. This is also called "Reflow."

  • Paint: The browser fills in the pixels for each element in memory. It draws out the text, colors, images, borders, and shadows. This happens on one or more "layers." This is also called "Repaint."

  • Compositing: The browser draws the layers to the screen in the correct order. Since this is just moving existing layers around, often on the GPU, it's the cheapest stage to run.

This diagram shows how different CSS property changes can skip the expensive stages. This is the key to performant updates.

Your job is to write CSS and JavaScript that triggers the pipeline as far to the right of this diagram as possible.

How your code triggers each stage

You can't optimize what you can't identify. You need to know which properties affect which stage.

Layout is triggered by any property that changes an element's geometry or position. Think width, height, margin, padding, border, top, left, or font-size. Changing a layout property is costly because it can cause a chain reaction, forcing the browser to recalculate the layout for a large part of the document.

Paint is triggered by properties that change an element's appearance without affecting its geometry. Think background-color, color, box-shadow, or outline. Paint is less expensive than Layout because a change to one element doesn't affect the position of others. But it's not free, especially if you're painting a large or complex area.

Compositing is the ideal path. This is what happens when you change properties that the GPU can handle directly, without needing to re-calculate layout or re-paint pixels. The main ones are transform and opacity. The browser just has to move the existing, already-painted element. This is why you always use transform: translateX(10px) for movement animations instead of changing left: 10px.

The interview question: "How would you animate an element moving across the screen smoothly?" Your answer starts with transform and explains why it's better by referencing this pipeline. You'd explain that animating left or margin-left triggers Layout on every frame, which is slow, while transform only triggers Compositing.

You can also give the browser a hint that an element will be animated by using will-change: transform, opacity. This encourages the browser to create a separate layer for the element ahead of time.

The trap: Don't overuse will-change. Every composited layer consumes GPU memory and resources. Applying it to too many elements can actually slow your site down. Use it only on elements that have complex, ongoing animations.

The biggest performance trap: Forced Synchronous Layout

Normally, the browser is smart. If you change ten styles in a row with JavaScript, it will batch them and run one single Layout calculation at the end of the task, just before it needs to paint the next frame.

However, you can break this batching. If you change a style and then immediately ask for a geometric value (like element.offsetHeight or element.getBoundingClientRect()), the browser has no choice. It must stop, run Layout synchronously, and give you the updated value.

Doing this in a loop is called "layout thrashing" or "forced synchronous layout," and it's a massive performance killer.

Here is what it looks like in code.

const badBox = document.getElementById('badBox');
const badBtn = document.getElementById('badBtn');

badBtn.addEventListener('click', () => {
  console.time('Layout Thrashing');
  for (let i = 0; i < 100; i++) {
    // WRITE: Change a style that affects layout
    badBox.style.width = `${100 + i}px`;

    // READ: Immediately read a layout property.
    // This forces the browser to perform a synchronous layout
    // for each and every iteration of the loop.
    console.log(`Current offsetWidth: ${badBox.offsetWidth}`);
  }
  console.timeEnd('Layout Thrashing');
});

This code forces 100 separate Layout calculations. An optimized version would perform all the reads first, then all the writes, allowing the browser to perform just one Layout at the end.

Try it

Take the "layout thrashing" code example above. Rewrite the click handler to avoid forcing a synchronous layout on every iteration. The goal is to separate the style reads from the style writes so the browser can batch the layout work. You won't be able to log the width on each iteration, and that's the point—the fix involves restructuring the logic to avoid that need.

Next: We'll dig deeper into the two most common performance killers in our lesson on Reflows and Repaints Explained.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

DOM, CSSOM and the Render Tree

Next

Reflows and Repaints Explained