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

未關閉
#176 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
30/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
react, typescript
領域
performance

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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).
主要語言
TypeScript
星號
581
分支
28
平均合併
13 小時 48 分鐘
30 天內合併 PR
45

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TanStack/redact 的其他 Issue

查看 TanStack/redact 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。