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

Đang mở
#176 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, typescript
Lĩnh vực
performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).
Ngôn ngữ chính
TypeScript
Star
581
Fork
28
Merge trung bình
13 giờ 48 phút
Pull request đã merge (30 ngày)
45

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/redact

Tất cả issue của TanStack/redact

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.