React Performance Optimization: From Slow to Lightning Fast
Master React performance with practical techniques including memoization, code splitting, virtual lists, and profiler-driven optimization.
· 4 min read
In this article9 sections
Why React Apps Get Slow
React is fast by default, but it is surprisingly easy to make it slow. The virtual DOM diffing algorithm is efficient, but if you trigger unnecessary re-renders across hundreds of components, even the best algorithm cannot save you.
Most React performance issues come from three sources: unnecessary re-renders, expensive computations running on every render, and loading too much JavaScript upfront.
Measuring Before Optimizing
Never optimize based on hunches. Use the React DevTools Profiler to identify which components re-render most often and which renders take the longest. The Profiler records every render and shows you exactly what triggered it.
Open React DevTools, switch to the Profiler tab, click Record, interact with your app, and stop recording. The flame chart shows render times for each component. Focus on the tallest flames first.
Preventing Unnecessary Re-Renders
React.memo for Function Components
Wrap components in React.memo when they receive the same props frequently but still re-render because their parent re-renders. React.memo does a shallow comparison of props and skips the render if nothing changed.
But be careful: if you pass objects or arrays as props, you need stable references. Creating new objects inline on every render defeats React.memo entirely.
useMemo for Expensive Calculations
If a component does expensive computation like filtering a large list or calculating statistics, wrap it in useMemo. This caches the result and only recalculates when the dependencies change.
Use useMemo for computations that take more than a few milliseconds. Do not use it for trivial calculations as the overhead of caching is not worth it.
useCallback for Stable Function References
When passing callbacks to memoized child components, wrap them in useCallback. Without it, you create a new function reference on every render, which breaks React.memo.
Code Splitting with React.lazy
Your users should not download your entire application upfront. Use React.lazy and Suspense to split your code into chunks that load on demand.
Route-based splitting is the easiest win: wrap each page component in React.lazy. Users download the code for a page only when they navigate to it. This can reduce your initial bundle by 50-80%.
For component-level splitting, use React.lazy on heavy components like charts, editors, or maps that are not immediately visible.
Virtualizing Long Lists
If you render a list with hundreds or thousands of items, the DOM gets overwhelmed. Libraries like react-window or @tanstack/virtual render only the visible items plus a small buffer, keeping DOM nodes to a minimum regardless of list size.
I have seen lists go from 2-second render times to instant by switching to virtualization. It is one of the highest-impact optimizations you can make.
State Management Optimization
Keep State Local
Do not lift state higher than necessary. If only one component needs a piece of state, keep it in that component. Lifting state to a parent causes the parent and all its children to re-render when that state changes.
Split Context Providers
If you use React Context, split your context into smaller pieces based on how often the data changes. One large context that combines user data, theme settings, and real-time notifications causes every consumer to re-render when any value changes.
Image and Asset Optimization
- Use lazy loading for images below the fold with loading="lazy"
- Serve images in WebP or AVIF format with proper fallbacks
- Use srcset for responsive images so mobile users do not download desktop-sized images
- Compress images with tools like Squoosh or sharp
Bundle Analysis
Run your build with the --analyze flag or use webpack-bundle-analyzer / rollup-plugin-visualizer to see exactly what is in your JavaScript bundle. Common culprits include importing all of lodash when you only need one function, unused dependencies that crept in over time, and large icon libraries when you only use a few icons.
Production Checklist
Before deploying, verify these optimizations are in place:
- React production build (no development warnings)
- Code splitting on routes at minimum
- Images optimized and lazy loaded
- No console.log statements
- Bundle size analyzed and unnecessary dependencies removed
- Core Web Vitals measured and within Google's thresholds
- React
- Performance
- JavaScript

Written by Pontus Henriksson
Co-founder and CEO of Walldy in Sundsvall. I have built for the web since I was fourteen, tested games for studios like Netflix and Bungie since 2021, and write about what I use in real projects.
Liked this? Get the next one.
New Claude skills, kits and what I learn building AI for small businesses. Not often, only when it is worth sending. Unsubscribe with one click.