Performance: Managing large applications
HIGH IMPACT
This affects initial page load speed, bundle size, and runtime responsiveness in large React apps.
import React, { Suspense, lazy } from 'react'; const BigComponentA = lazy(() => import('./BigComponentA')); const BigComponentB = lazy(() => import('./BigComponentB')); export default function App() { return ( <> <Suspense fallback={<div>Loading A...</div>}> <BigComponentA /> </Suspense> <Suspense fallback={<div>Loading B...</div>}> <BigComponentB /> </Suspense> </> ); }
import { BigComponentA } from './BigComponentA'; import { BigComponentB } from './BigComponentB'; export default function App() { return ( <> <BigComponentA /> <BigComponentB /> </> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Import all components upfront | High (all nodes loaded) | Multiple reflows on load | High paint cost | [X] Bad |
| Lazy load components with React.lazy | Reduced initial nodes | Single reflow on load | Lower paint cost | [OK] Good |
| Prop drilling global state | Many re-renders | Many reflows on state change | High paint cost | [X] Bad |
| Use React Context for global state | Fewer re-renders | Fewer reflows | Lower paint cost | [OK] Good |
| Inline event handlers per item | Many function recreations | No direct reflow but high CPU | Higher paint cost due to CPU | [X] Bad |
| Memoized shared event handler | Single function instance | No extra reflows | Lower paint cost | [OK] Good |