0
0
Reactframework~8 mins

Managing large applications in React - Performance & Optimization

Choose your learning style9 modes available
Performance: Managing large applications
HIGH IMPACT
This affects initial page load speed, bundle size, and runtime responsiveness in large React apps.
Loading a large React application all at once
React
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>
    </>
  );
}
Loads components only when needed, reducing initial bundle size and speeding up first paint.
📈 Performance GainReduces initial bundle size by 30-70%, improving LCP and INP significantly.
Loading a large React application all at once
React
import { BigComponentA } from './BigComponentA';
import { BigComponentB } from './BigComponentB';

export default function App() {
  return (
    <>
      <BigComponentA />
      <BigComponentB />
    </>
  );
}
Imports all large components upfront, increasing bundle size and blocking initial render.
📉 Performance CostBlocks rendering until entire bundle loads, increasing LCP by 1-3 seconds on slow networks.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Import all components upfrontHigh (all nodes loaded)Multiple reflows on loadHigh paint cost[X] Bad
Lazy load components with React.lazyReduced initial nodesSingle reflow on loadLower paint cost[OK] Good
Prop drilling global stateMany re-rendersMany reflows on state changeHigh paint cost[X] Bad
Use React Context for global stateFewer re-rendersFewer reflowsLower paint cost[OK] Good
Inline event handlers per itemMany function recreationsNo direct reflow but high CPUHigher paint cost due to CPU[X] Bad
Memoized shared event handlerSingle function instanceNo extra reflowsLower paint cost[OK] Good
Rendering Pipeline
Managing large apps affects how much JavaScript the browser must parse and execute before painting. Lazy loading reduces initial JavaScript parsing. Using context and memoization reduces React re-renders, lowering layout and paint costs.
JavaScript Parsing
Style Calculation
Layout
Paint
Composite
⚠️ BottleneckJavaScript Parsing and Layout due to large bundles and frequent re-renders.
Core Web Vital Affected
LCP, INP
This affects initial page load speed, bundle size, and runtime responsiveness in large React apps.
Optimization Tips
1Split large React apps with lazy loading to reduce initial bundle size.
2Use React Context to manage global state and avoid prop drilling.
3Memoize event handlers to reduce memory usage and improve responsiveness.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using React.lazy for large components?
AIt prevents any re-renders in the app.
BIt automatically caches all components in memory.
CIt reduces the initial JavaScript bundle size, speeding up first paint.
DIt disables JavaScript parsing for those components.
DevTools: Performance
How to check: Record a performance profile while loading the app and interacting. Look for long scripting tasks and frequent layout recalculations.
What to look for: High scripting time and many layout events indicate poor code splitting or excessive re-renders.