Home / Articles / Practical notes: How I Optimized a Slow React App Without Rewriting It

This article is published in English.

Practical notes: How I Optimized a Slow React App Without Rewriting It

Operable walkthrough of Practical notes: How I Optimized a Slow React App Without Rewriting It: contracts, checks, and drop-in code slots for teams shipping this pattern.

1621 words

Use this as an operator-facing rebuild of the ideas in “How I Optimized a Slow React App Without Rewriting It”: clear stages, ordered code slots, and recovery notes that survive a handoff. The Overview stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.

The Diagnosis: Finding the Problem

For the The Diagnosis Finding the stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

1. React.memo: The Easiest Win

For the 1 React memo The stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

const ExpensiveComponent = React.memo(({ data, onUpdate }) => {
  // Component logic
});

2. useMemo and useCallback: Stopping Recursive Recalculations

For the 2 useMemo and useCallback stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see. For the 2 useMemo and useCallback stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.

const computedStats = useMemo(() => {
  return expensiveAggregation(data);
}, [data]);
const handleUpdate = useCallback((id) => {
  updateItem(id);
}, []);

3. useTransition: Prioritizing User Interactions

When working through the 3 useTransition Prioritizing User stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

const [isPending, startTransition] = useTransition();
const handleSearch = (term) => {
  startTransition(() => {
    setSearchTerm(term);
    // Filtering happens in the background
  });
};

4. useDeferredValue: Smoothing Out Expensive Renders

When working through the 4 useDeferredValue Smoothing Out stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

const deferredData = useDeferredValue(data);
// Chart receives deferredData and updates only when React has idle time

5. Virtualization: Rendering Only What’s Visible

When working through the 5 Virtualization Rendering Only stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Treat effects as synchronization with the outside world, not as a substitute for derived values during render. When working through the 5 Virtualization Rendering Only stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.

import { FixedSizeList } from 'react-window';
const Row = ({ index, style }) => (
  <div style={style}>
    {data[index].name}
  </div>
);
<FixedSizeList
  height={400}
  itemCount={data.length}
  itemSize={35}
  width="100%"
>
  {Row}
</FixedSizeList>

6. Lazy Loading: Code Splitting By Route

The 6 Lazy Loading Code stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

const Dashboard = lazy(() => import('./views/Dashboard'));
const Analytics = lazy(() => import('./views/Analytics'));
function App() {
  return (
    <Suspense fallback={<Loading />}>
      <Routes>
        <Route path="/" element={<Dashboard />} />
        <Route path="/analytics" element={<Analytics />} />
      </Routes>
    </Suspense>
  );
}

7. useMemoizedSelector: State Management Optimization

The 7 useMemoizedSelector State Management stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

import { createSelector } from '@reduxjs/toolkit';
const selectFilteredData = createSelector(
  (state) => state.items,
  (state) => state.filterTerm,
  (items, term) => items.filter(item =>
    item.name.toLowerCase().includes(term.toLowerCase())
  )
);
// In component:
const filteredData = useSelector(selectFilteredData);

The Numbers: Before and After

The The Numbers Before and stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs. The The Numbers Before and stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.

The Mindset Shift

For the The Mindset Shift stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

The Bottom Line

For the The Bottom Line stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

Operational checklist

When working through the Operational checklist stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest.

Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline.

Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

Pin dependency versions and record the image digest that ran the demo. Reproducibility beats tribal knowledge.

Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.

Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

Before promoting the stack, freeze versions, capture a golden transcript for the critical path, and confirm rollback steps. Shared environments need rate limits, tenancy checks, and a clear owner for secret rotation. Prefer boring reliability over clever one-off demos.

Batch note for d6a7f4e83dda: keep provider keys out of the repo, set a per-session token ceiling, and store transcripts next to the eval fixtures so later model swaps stay comparable.