An Activity that rerenders in the same mode walks its whole retained subtree

Abierto
#176 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
react, typescript
Área
performance

Línea de trabajo

Start with renderActivity in dom/features/activity/full.ts and trace its prepare/syncDom and reconnect walks for an Activity whose mode stays the same. The issue includes a reproducer and reports tests on an existing branch, including a fiber read count test; inspect those tests and verify reveal and hide behavior remains unchanged. Done means same-mode rerenders skip the retained subtree walk while mode changes still process it.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Rerendering an <Activity> whose mode did not change still walks every retained fiber below it, twice. With 2,000 memoized rows inside, a parent rerender takes 28 ms per update on main, against 0.04 ms on React 19.3.0, which only traverses an Activity's subtree when its visibility changes.

import { Activity, memo, useLayoutEffect, useState } from 'react'

const Row = memo(({ id }: { id: number }) => {
  useLayoutEffect(() => () => {}, [])
  return <li>{id}</li>
})
const Rows = memo(() => <ul>{Array.from({ length: 2000 }, (_, id) => <Row key={id} id={id} />)}</ul>)

export function Example() {
  const [tick, setTick] = useState(0)
  return <>
    <button onClick={() => setTick(value => value + 1)}>Rerender {tick}</button>
    <Activity mode="visible"><Rows /></Activity>
  </>
}

renderActivity (dom/features/activity/full.ts) runs its prepare/syncDom walk and its reconnect walk on every render. Walking only when the mode changes is enough: children that render are already prepared and synced as they render, the rest keep the state the last mode change gave them, and an Activity above that changes mode walks the subtree itself.

That is 13 lines, and I have it on a branch with tests, since PRs are limited to collaborators. Happy to open one if you want it, or take the idea as is:
https://github.com/TanStack/redact/compare/main...santiago-ramos-02:redact:perf/activity-skip-activity

  • Speed: same-mode rerender 28.0 to 1.15 ms per update, -95.9% (95% interval -96.3% to -89.8%). Reveal and hide are unchanged.
  • Size: +9 B gzip on the default client (23,411 to 23,420), 0 on nano. Every fixed budget in size-check.mjs passes unchanged.
  • Tests: on the branch, including one that counts fiber reads over the retained subtree during a same-mode rerender and fails on main (301 per Activity, expected 0).
Lenguaje dominante
TypeScript
Estrellas
581
Forks
28
Merge medio
13 h 48 min
PR fusionados (30 d)
45

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/redact

Todos los issues de TanStack/redact

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.