Skip to content

perf(mobile): skip re-rendering unchanged worktree rows - #28058

Merged
Jinwoo-H merged 3 commits into
mainfrom
mobile-worktree-row-memo
Oct 13, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
mobile-worktree-row-memo

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​195
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36 $\color{#cf222e}{\Huge{\mathbf{−}}}$​176 $\color{#cf222e}{\Huge{\mathbf{−}}}$​140

What

Every visible workspace row on mobile re-rendered on every changed worktree.ps poll (every 3 s while any agent is printing), even when only one row changed.

WorktreeListRow was wrapped in a default memo, but it never skipped. Rows arrive freshly JSON-parsed on each poll, and buildSections copies each row to add sectionListKey, so the item prop is always a new object.

Change

  • New structural-equality.ts: a ~20-line areStructurallyEqual. Objects and arrays compare by value, recursively; everything else, including functions, compares with Object.is.
  • WorktreeListRow = memo(WorktreeListRowComponent, areStructurallyEqual). item and repoIcon compare by value. Callbacks and now compare 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 to Worktree can't be silently missed.
  • Row props are typed Worktree instead of a generic structural subset, which removes the as typeof cast 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 undefined now 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 now prop (useNow(30_000)), which drives the "2m" labels and the stale-to-idle dot decay. now compares 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:

Row renders per poll Render time per poll
Before 200 4.4–12.7 ms
After 1–2 1.7–2.1 ms

The on-device gain should be larger, since real row children aren't mocked (estimate; not measured on a device).

Tests

  • Unit tests for areStructurallyEqual.
  • Row tests rendering WorktreeListRow directly. A value-equal item or a fresh repoIcon doesn't re-render. A new now, a changed nested agent field, or a new callback does.
  • One list-level test with real buildSections and 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.

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
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The new areStructurallyEqual function recursively compares objects and arrays. areWorktreeListsEqual and WorktreeListRow now use this comparator. The row component accepts the shared Worktree type. Tests cover structural comparison and row rerenders when worktree data or row props change.


Priority: ➖ Normal

Merge Risk: 🔵 Low · up to ff156

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 · Passed 3 · Failed 2

Failed Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description provides strong technical detail about the problem, implementation, rationale, measurements, tests, and shipping impact. However, it omits required template elements, including the lin… Add the required Linked Issue reference. Add before-and-after visual proof, or state N/A with a reason if visual proof is not applicable. Complete the template sections and checklist, including testing and review details.
Passed Passed checks (3 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the primary change: preventing unnecessary re-renders of unchanged mobile worktree rows.

Full details: Description check

Explanation

The description provides strong technical detail about the problem, implementation, rationale, measurements, tests, and shipping impact. However, it omits required template elements, including the linked issue and visual proof or an explicit N/A statement for this behavior change.


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e785a2a5-9dba-4528-a35b-6a809a640542
📥 Commits

Reviewing files that changed from the base of the PR and between cfc49db and ff15616.

📒 Files selected for processing (7)
  • mobile/src/components/WorktreeListRow.test.ts
  • mobile/src/components/WorktreeListRow.tsx
  • mobile/src/host-screen/host-workspace-list-row-memo.test.tsx
  • mobile/src/worktree/structural-equality.test.ts
  • mobile/src/worktree/structural-equality.ts
  • mobile/src/worktree/worktree-list-snapshot.test.ts
  • mobile/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.

@Jinwoo-H
Jinwoo-H merged commit 0c42285 into main Oct 13, 2026
21 checks passed
@Jinwoo-H
Jinwoo-H deleted the mobile-worktree-row-memo branch October 13, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant