Skip to content
Source
Sign inSign up
TanStack/redact

perf: Re-renders take ~2× the CPU of React 19.3 in two production TanStack Start sites (0.2.0) #75

Send to my agent
Openquanglam2807(GitHub profile, opens in a new tab) opened this issue 2 comments

We evaluated Redact 0.2.0 on our two marketing sites, webcatalog.io and lexibird.com. Both run TanStack Start on Cloudflare Workers.

Adopting it was a drop-in change: builds, SSR, hydration and client-side navigation all worked. The size saving matched the announcement, and hydration blocked the main thread less than React's. But updates after load cost about 2× more CPU than React 19.3.1, and clicks that re-render a large part of the page became about twice as slow. Numbers, method, and CPU profiles and DevTools traces below.

Setup

  • @tanstack/redact 0.2.0: redact() placed first in the plugins list with default options (full preset). No other changes.
  • @tanstack/react-start 1.169.3, @tanstack/react-router 1.170.45, react/react-dom 19.3.1
  • vite 8.3.5 (Rolldown), @vitejs/plugin-react 6.1.2 with the React Compiler (babel-plugin-react-compiler 1.0.0)
  • @cloudflare/vite-plugin 1.64.0 (plain plugin, not @tanstack/redact/cloudflare)
  • UI: Tailwind 4 with @base-ui/react 1.9.0 (Tabs, Accordion)
  • Production builds served by vite preview (workerd), behind a local brotli proxy so transfer sizes match production. Headless Chromium on Linux x64 (a shared cloud container), with 4× CPU throttling applied via CDP (Emulation.setCPUThrottlingRate).

Bundle size: as advertised

The JS+CSS each page loads, from the TanStack Start route manifest plus its static imports:

PageReact (gzip)Redact (gzip)Saved
webcatalog.io home444.6 KB397.3 KB−47.3 KB
webcatalog.io pricing417.2 KB370.3 KB−46.9 KB
lexibird.com home352.1 KB305.2 KB−46.9 KB
lexibird.com pricing361.3 KB314.2 KB−47.1 KB

That's about 44 KB less transferred with brotli on every page, in line with the 47.0 KB in the Start row of the announcement.

Interaction latency: ~2× slower

Each pricing page has a billing-cycle Tabs that re-renders all of the page's pricing cards, plus a FAQ Accordion. We toggled the tab 9 times and opened 4 FAQ items per load, in a 412×915 viewport. Each interaction's duration is the max Event Timing duration for its interactionId, the same input INP uses. There were 6 loads per runtime, alternating React and Redact builds.

InteractionReact 19.3.1 median (range)Redact 0.2.0 median (range)
lexibird.com/en/pricing: billing tab104 ms (72–200)200 ms (144–368)
webcatalog.io/en/pricing: billing tab116 ms (72–216)252 ms (184–400)
webcatalog.io/en/pricing: FAQ accordion220 ms (worst 952)428 ms (worst 1536)
lexibird.com/en/pricing: FAQ accordion68 ms (worst 360)76 ms (worst 352)

The small Lexibird FAQ update is unchanged, so the cost seems to scale with how much of the tree re-renders.

This doesn't look like the missing time slicing that the compatibility notes describe. React renders discrete click updates synchronously (SyncLane) too, so neither runtime yields during these updates.

Profiles: where the time goes

We recorded a V8 CPU profile (100 µs sampling) and, in a separate pass, a DevTools trace of 10 billing-tab clicks and of the page load. That's 3 rounds per site and runtime, with 4× CPU throttling. "Runtime CPU" is sampled self time in react-dom/react/scheduler or in @tanstack/redact, attributed through our build's source maps.

10 billing-tab clicks:

PageRuntime CPU, ReactRuntime CPU, RedactMedian click task, React → Redact
lexibird.com/en/pricing422 / 554 / 872 ms1459 / 1548 / 1644 ms143 → 268 ms
webcatalog.io/en/pricing948 / 951 / 983 ms1754 / 1986 / 2061 ms158 → 308 ms

The top Redact frames during clicks (webcatalog.io, round 1, self time) were:

  • rememberFiber (dom/commit.js:143), 158 ms
  • renderHost (dom/reconcile.js:793), 113 ms
  • commitPlacements (dom/reconcile.js:1044), 102 ms
  • useEffectImpl (dom/dispatcher.js:134), 74 ms
  • the anonymous function at dom/commit.js:146, 71 ms
  • renderFunction (dom/reconcile.js:429), 62 ms
  • renderWithHooks (dom/dispatcher.js:76), 60 ms
  • reconcile (dom/reconcile.js:907), 55 ms
  • readContext (dom/reconcile.js:774), 51 ms

commitPlacements is not doing extra DOM work. We counted mutations per billing-tab click with a MutationObserver, and the DOM changes are identical under both runtimes: 12 attribute changes, plus 2 text changes on webcatalog.io and 4 on lexibird.com, with no nodes re-inserted. So the extra time goes into render and commit bookkeeping, not DOM writes.

Page load (navigation until network idle + 1.5 s): load came out better. Main-thread blocking time (the sum over 50 ms of each long task, from the trace) was:

PageReactRedact
lexibird.com/en/pricing1181–1458 ms418–595 ms
webcatalog.io/en/pricing973–1468 ms456–719 ms

The longest task dropped from 377–500 ms to about 220 ms. Total sampled runtime CPU during load was higher under Redact (1.7–2.2 s against 0.45–0.51 s on webcatalog.io), but it was spread over shorter tasks. The Redact load profiles also reach a stack depth of about 378 frames, against 90–170 for React, through walkRetained (dom/walk.js:1), adoptHostDom and hydrateProps (hydration/full.js). That depth may inflate the sampling profiler's numbers, so we'd trust the trace's blocking times more than the CPU totals here.

One oddity: under Redact, a trivial scroll listener in our header showed 60–110 ms of self time during load, on every webcatalog.io round. It runs once on mount and calls setIsScrolled(window.scrollY > 0) from a useEffect. Under React it never appears among the top functions. It might be a synchronous re-render triggered by setState inside a passive effect during hydration being attributed to the caller, but we haven't confirmed that.

Lighthouse, for completeness

Mobile, default simulated throttling, third parties blocked; medians of 7 runs. The simulated TBT got worse under Redact, which contradicts the real-throttling traces above, so we'd discount it:

PageScoreLCPTBT (simulated)CLS
lexibird.com/en75 → 714.83 → 4.62 s290 → 413 ms0.001 → 0.001
lexibird.com/en/pricing82 → 683.06 → 3.10 s467 → 1549 ms0 → 0
lexibird.com/en/solutions/ai-translation80 → 704.69 → 3.30 s127 → 1002 ms0.001 → 0.001
webcatalog.io/en/pricing79 → 673.72 → 3.69 s407 → 1073 ms0 → 0
webcatalog.io/en/about72 → 834.39 → 3.65 s560 → 330 ms0 → 0
webcatalog.io/en/legal/privacy-policy85 → 773.69 → 3.40 s386 → 727 ms0 → 0

Attached

redact-traces.zip contains round 1 for both sites and both runtimes:

  • *-load.trace.json and *-clicks.trace.json: DevTools traces you can load in Chrome's Performance panel.
  • *.cpuprofile: V8 CPU profiles from a separate pass, so the tracer doesn't skew them.

The scripts are minified and we haven't attached our source maps; the function names above are mapped to Redact's sources (dist/). Both pricing pages are public (/en/pricing on each site) if you'd like to reproduce with your own builds.

Not verified

  • Whether the React Compiler matters. It's on in both builds and may interact with Redact differently, for example through react/compiler-runtime → @tanstack/redact/compiler-runtime.
  • Real devices. All numbers come from one shared Linux container with CPU throttling; we didn't measure on phones.
  1. We investigated a similar update regression with Redact 0.2.1 and found a smaller reproduction that may help narrow this down: cached JSX retains its identity, but Redact re-enters child subtrees that the React control skips. React Compiler makes the performance difference much larger in our component fixture.

    We have not tested your two sites, so this is evidence for a possible contributing mechanism, not confirmation that both reports have exactly the same cause.

    Minimal reproduction: unchanged JSX, without React Compiler

    Tested versions: react / react-dom 19.3.0, @tanstack/redact 0.2.1, Vite 8.3.0, @vitejs/plugin-react 6.1.1.

    The minimal fixture uses the React plugin with Compiler disabled, no StrictMode, and no Base UI, external store, router, hydration, or backend. For a standalone Vite reproduction, use an index.html containing <div id="root"></div> and <script type="module" src="/main.tsx"></script>, and select the runtime in the config:

    import { defineConfig } from 'vite';
    import react from '@vitejs/plugin-react';
    import { redact } from '@tanstack/redact/vite';
    
    export default defineConfig({
      plugins: [react(), ...(process.env.RENDERER === 'redact' ? [redact({ preset: 'full' })] : [])],
    });

    main.tsx:

    import { useState, useMemo, useLayoutEffect, version } from 'react';
    import { createRoot } from 'react-dom/client';
    
    const probe = {
      version,
      parentRenders: 0,
      childRenders: 0,
      childEffects: 0,
      elementCreations: 0,
      stableElementReuses: 0,
    };
    let previousChild: unknown;
    Object.assign(window, { __probe: probe });
    
    function Child() {
      probe.childRenders++;
      const [value, setValue] = useState(0);
      useLayoutEffect(() => {
        probe.childEffects++;
      });
      return (
        <section>
          <span>{value}</span>
          <button onClick={() => setValue(value + 1)}>Update child</button>
        </section>
      );
    }
    
    function App() {
      probe.parentRenders++;
      const [value, setValue] = useState(0);
      const child = useMemo(() => {
        probe.elementCreations++;
        return <Child />;
      }, []);
      if (previousChild === child) probe.stableElementReuses++;
      previousChild = child;
      return (
        <main>
          <button onClick={() => setValue(value + 1)}>Update parent</button>
          <span>{value}</span>
          {child}
        </main>
      );
    }
    
    createRoot(document.getElementById('root')!).render(<App />);

    Build each runtime separately in production mode, serve its output, click Update parent five times, and inspect window.__probe:

    RENDERER=react bunx vite build --outDir dist-react
    RENDERER=react bunx vite preview --outDir dist-react --port 4173
    # Stop that preview, then build/serve the other runtime:
    RENDERER=redact bunx vite build --outDir dist-redact
    RENDERER=redact bunx vite preview --outDir dist-redact --port 4173

    Observed after initial mount plus five parent updates:

    CounterReactRedact
    Parent renders66
    Element creations inside useMemo11
    Same-element identity reuses55
    Child renders16
    Child layout effects16

    Clicking Update child afterward changes its displayed state in both runtimes; child-render totals become 2 and 7 respectively. The memo cache is retained in both. The difference is whether unchanged JSX prevents downstream rendering/effect work. This is an observed optimization difference, not a claim that React guarantees a particular render count in every situation.

    Compiler on/off in a 300-row component fixture

    We also tested a production-built fixture using real shopping-list row components, Base UI 1.8.0 checkboxes/inputs, icons, i18n and an in-memory useSyncExternalStore source. One checkbox update changes one row's record; the other 299 records retain identity. There are no network or persistence operations in the measured path.

    Compiler settingReact medianRedact median
    Enabled in both builds8.00 ms111.25 ms
    Disabled in both builds127.35 ms137.95 ms

    Disabling Compiler largely removes the relative gap by making React much slower; it does not improve Redact. The per-block Compiler-enabled medians were 7.90 / 8.15 / 8.00 ms for React and 109.30 / 114.30 / 109.00 ms for Redact.

    Explicit memo intervention

    In a separate paired control, keeping Compiler enabled and wrapping the row component in memo(ListItem) reduced most of the gap:

    Row componentReact medianRedact median
    Without explicit memo8.00 ms108.95 ms
    With explicit memo2.50 ms3.15 ms

    Props are stable enough for memoization in this compiled fixture. This does not establish that adding memo to arbitrary application components is sufficient.

    Separate diagnostic probes found one store notification and one parent commit per row update with either runtime. Base UI's native-input .labels accesses were 1 with React, 300 with Redact, and back to 1 with explicit row memoization under Redact. CPU sampling also highlighted reconciliation/commit work and Base UI's useAriaLabelledBy layout effect. That hook runs after each committed render, so revisiting unchanged controls amplifies the cost. The minimal reproduction above does not need Base UI to expose the subtree-rendering difference.

    In the installed 0.2.1 sources, renderFunction / renderChildChain in src/dom/reconcile.ts and the separate equality gate in src/dom/features/memo/full.ts are useful places to investigate. A general bailout would need to preserve independently scheduled descendant state, context and Suspense behavior; we have not validated a general-purpose runtime patch.

    Measurement limits

    • Environment: Apple M3 Max, macOS 27.0.1, headless Chromium 153.0.8010.12, 4× CPU throttling via CDP, loopback static serving of production builds. These are local component-fixture results, not measurements of deployed sites or phones.
    • Each timing variant had three blocks with runtime order reversed between blocks, two row-update warmups and eight measured updates per block: 24 samples per variant. Each interaction checked the resulting checkbox state. This is a small sample, without a confidence interval; the exact ratio should not be generalized.
    • Timing starts inside the row-update handler and ends in the parent's layout effect after commit. It excludes input dispatch delay and actual display paint, and is not INP, end-to-end shopping latency, or durable-storage time. It should not be compared directly with the Event Timing durations in the original issue.
    • Runs shared a browser session and warm browser/OS caches; they were not fresh-process or cold-network experiments. No mobile-device, memory/leak or server-performance conclusion is supported.
    • CPU profiles and DOM counters were collected separately from the timing fixtures. An exploratory render-phase counter changed Compiler optimization; we excluded that run and kept render instrumentation out of the timing comparisons. The counters in the minimal example are intentional and Compiler is disabled there.
    • The row fixture is application-specific, while the JSX identity example is standalone. These observations help isolate a candidate mechanism; they do not establish complete React compatibility or prove that every re-render regression has this cause.
  2. I tried Redact 0.2.2 on my portfolio: Next.js 16.4.2, Pages Router, Turbopack, React 19.3.1. Initial JS dropped by ~34 kB gzip (18%), but Lighthouse startup TBT went up on most pages:

    PageReact TBTRedact TBT
    /45 ms119 ms
    /blog74 ms72 ms
    /about77 ms144 ms
    /blog/react-rerender68 ms166 ms

    Medians of five runs per page and runtime, 40 runs total. Lighthouse 13.6.0 mobile simulation, slow 4G, 4× CPU, Apple M4 Pro. I alternated runtime order and used a fresh browser context/cache each time. No runtime or console errors.

    React ran on Vercel Production, Redact on Preview, so hosting may affect the results. This is simulated startup TBT; I haven't measured interaction latency or validated it with actual CPU throttling.

    0.2.2 fixed the hydration loop, but I still needed local patches for SVG attributes (#81) and Children.toArray keys (#37). Those patches were included in the measurements.

    I closed the migration PR and kept React. The code, patches and full comparison are there.

  3. tannerlinsley linked this to #133

Sign in to join this conversation.