Repository navigation
perf(mobile): skip re-rendering unchanged worktree rows - #28058
Conversation
Rows reach the host list freshly parsed and copied on every changed worktree.ps poll, so the row memo never skipped and every mounted row re-rendered each poll. The row memo now compares the item by value with the catalog's areWorktreesEqual, extended to every Worktree and agent row field, and every other prop by identity. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to In rare cases, a poll that only changes a missing agents field to an empty one can trigger an unnecessary list refresh. This is a small efficiency regression, so it is mergeable with a follow-up to restore the normalization. Pre-merge checks ·
|
The hand-written Worktree field list needed a completeness guard that no compiler checks, since mobile test files sit outside tsc. A generic structural equality covers every field by construction, so a new field can never be skipped and freeze a row. Rows memo on it directly: the item and repo icon compare by value, callbacks and `now` by identity. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e785a2a5-9dba-4528-a35b-6a809a640542
📒 Files selected for processing (7)
mobile/src/components/WorktreeListRow.test.tsmobile/src/components/WorktreeListRow.tsxmobile/src/host-screen/host-workspace-list-row-memo.test.tsxmobile/src/worktree/structural-equality.test.tsmobile/src/worktree/structural-equality.tsmobile/src/worktree/worktree-list-snapshot.test.tsmobile/src/worktree/worktree-list-snapshot.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
What
Every visible workspace row on mobile re-rendered on every changed
worktree.pspoll (every 3 s while any agent is printing), even when only one row changed.WorktreeListRowwas wrapped in a defaultmemo, but it never skipped. Rows arrive freshly JSON-parsed on each poll, andbuildSectionscopies each row to addsectionListKey, so theitemprop is always a new object.Change
structural-equality.ts: a ~20-lineareStructurallyEqual. Objects and arrays compare by value, recursively; everything else, including functions, compares withObject.is.WorktreeListRow = memo(WorktreeListRowComponent, areStructurallyEqual).itemandrepoIconcompare by value. Callbacks andnowcompare by identity, so new props are covered automatically.areWorktreeListsEqual(the catalog's "did anything change" check) uses the same function. The hand-written field-by-field equality is deleted, so a field added toWorktreecan't be silently missed.Worktreeinstead of a generic structural subset, which removes theas typeofcast and the duplicate type.The comparator is at the row on purpose. Rows are re-spread in three places before rendering (display overrides, lineage, sections), so keeping object identity alive would need a cross-render cache.
A missing key and an explicit
undefinednow count as different. That fails safe: at worst one extra render, never a stale row. Catalog rows are raw JSON, so this doesn't flip-flop between polls.Time-based rendering
The row's only time input is the
nowprop (useNow(30_000)), which drives the "2m" labels and the stale-to-idle dot decay.nowcompares by identity, so every row still re-renders on each 30 s tick. A test covers this. Repo icons, refreshed every 60 s as new objects, no longer re-render every row.Measured
Node + react-test-renderer, 200 rows each with an agent, 50 polls with one row changing per poll, row children mocked:
The on-device gain should be larger, since real row children aren't mocked (estimate; not measured on a device).
Tests
areStructurallyEqual.WorktreeListRowdirectly. A value-equal item or a freshrepoIcondoesn't re-render. A newnow, a changed nested agent field, or a new callback does.buildSectionsand JSON-cloned polls: only the changed row re-renders.Shipping
Nothing changes on the wire. On phones running the OTA shell, the host list is the desktop-served page, so this reaches them with a desktop update. The native list needs the next app release.