Repository navigation
perf: stop re-rendering the rooms list swipe layer on row content changes - #7971
diegolmello wants to merge 2 commits into
Conversation
…nges Split RoomItemContainer so the swipe layer (Touchable) subscribes only to the fields it uses (rid, type, favorite, read state), while a new RoomItemContent subscribes to the full record and renders the row. A new message now re-renders the row content without rebuilding the pan gesture and its worklets. Touchable and the long-press handler read the server version at call time instead of holding a redux subscription per row.
How the row render split worksComponent tree. The swipe layer moved out of <RoomItemContainer> useRoomSnapshot(item): full record
- <RoomItem>
- <Touchable> pan gesture, worklets, shared values
- <Wrapper> … row markup
+ <Touchable> swipe fields from useRoomSwipeState(item)
+ <RoomItemContent> useRoomSnapshot(item): full record
+ <RoomItem>
+ <Wrapper> … row markupWhat a new message re-renders sequenceDiagram
participant DB as WatermelonDB record
participant C as RoomItemContainer
participant T as Touchable
participant RC as RoomItemContent
DB->>C: change (unread, lastMessage)
Note over C: swipe state {rid, type, favorite, isRead} is unchanged,<br/>so the cached selection is returned and nothing renders
DB->>RC: change
RC->>RC: new snapshot, re-render the row content
Note over T: not rendered
When the swipe layer does re-render. Per-row work removed outside renders Touchable
- useAppSelector(server.version) # one redux subscription per row
+ store.getState().server.version # read when mark read/unread runs
- direction = isRTL ? -1 : 1 # every render
+ direction # once per module |
|
No actionable comments were generated in the recent review. WalkthroughRoom item state, content rendering, and touch interactions now use separate hooks and components. The container composes these parts, and the tests cover room updates, swipe state, and long-press handling. ChangesRoom item rendering and interaction
Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Refactor Sequence Diagram(s)sequenceDiagram
participant RoomItemContainer
participant useRoomSwipeState
participant Touchable
participant RoomItemContent
participant RoomItem
RoomItemContainer->>useRoomSwipeState: Read room swipe state
RoomItemContainer->>Touchable: Pass swipe state and touch handlers
RoomItemContainer->>RoomItemContent: Pass item and display properties
RoomItemContent->>RoomItem: Pass derived room display data
Suggested labels: Suggested reviewers: Merge Risk:
|
Proposed changes
Rows in the rooms list rebuilt their swipe layer (
Touchable: the pan gesture, its worklets and shared values) whenever the row's content changed.memo(Touchable)never skipped a render, becauseRoomItempassed it a newchildrenelement every time. So every new message, unread count change or last-message update re-ran the whole swipe setup for that row.The row is now split into two layers:
RoomItemContainersubscribes only to what the swipe layer uses (rid, type, favorite, read state) throughuseRoomSwipeState, and rendersTouchable.RoomItemContentsubscribes to the full record and renders the presentationalRoomItem, which no longer wrapsTouchable.A content-only update now re-renders the row content and leaves the swipe layer alone. Becoming read or unread, or being favorited, still re-renders the swipe layer, because its actions depend on those fields.
Two smaller cuts to per-row work:
Touchableand the long-press handler read the server version from the store when an action runs, instead of holding a redux subscription per row.Measured on an iOS simulator with a debug build, using the React DevTools profiler while 5 messages arrived in one room (two runs on each side):
Touchablerenders per new messageA Jest benchmark that mounts 100 real rows and updates each one's unread count shows the same direction: about 30 ms down to 7–17 ms per update of all rows. Mount time is unchanged (about 50 ms per 100 rows).
Issue(s)
How to test or reproduce
Screenshots
Rooms list renders (iOS simulator, debug build)
Rooms list renders
a-rooms-list-expanded.mp4
New message updates the row live
New message updates the row live
b-new-message-updates-row.mp4
Swipe right stays open, tap closes it
Swipe right stays open, tap closes it
c-swipe-right-stays-open-tap-closes.mp4
Swipe left, then another row's swipe closes it
Swipe left, closed by another row
d-swipe-left-closed-by-other-row.mp4
Tap opens the room
Tap opens the room
e-tap-row-opens-room.mp4
Mark read from the swipe action turns the row read
Mark read turns the row read
f-mark-read-flips-row-to-read.mp4
Types of changes
Checklist
Further comments
RoomItemContainerRenders.test.tsxfails on develop: a content-only update renders the swipe layer twice instead of once. It passes here.I also tried dropping the
useAnimatedReactionthat mounts and unmounts the swipe actions, but I left it out: it showed no measurable gain, and with two fingers it could leave a row moving with no actions behind it.Summary by CodeRabbit