Repository navigation
Description
Coming from https://expensify.slack.com/archives/C05LX9D6E07/p1779369728592709
Background:
Each opened chat owns a Report subscribed from Onyx and renders one ReportActionItem per row; an active session keeps hundreds mounted. Onyx pushes a fresh top-level Report reference whenever the backend updates routine fields tied to chat activity, which happens on every incoming or sent message. The action list also recomputes per-row metadata when any row is inserted. ReportActionItem is wrapped in an outer PureReportActionItem layer with React.memo, but most of the heavy children inside it now own their own Onyx subscriptions and memoization.
Problem:
When a user has a long chat open and is actively scrolling or composing, if a message is sent or received in that chat, every visible ReportActionItem re-renders unnecessarily, dropping frames and producing visible jank.
Solution:
-
Add typed getStableReportSelector: a useOnyx selector that returns a Report projection with the fields tied to chat-activity churn stripped (lastMessageText, lastVisibleActionCreated, lastReadTime, lastReadSequenceNumber, lastMentionedTime, lastVisibleActionLastModified, lastMessageHtml, lastActorAccountID, lastActionType). useOnyx compares selector output with deepEqual, so when only stripped fields change, the subscribed component sees the same projection reference and skips re-rendering. Every other Report field is kept, which intentionally minimizes the risk of regressions in downstream consumers that read fields we haven't explicitly profiled.
This is a deliberate short-term bridge: it stops heartbeat re-renders without rewriting the tree, but the long-term fix is narrower row dependencies (see Follow-ups), not a permanent “stable Report” API. -
Replace the per-row index prop with ReportActionIndexContext. The only descendant that reads the index now is ReportActionItemMessageEdit (for scroll-to-index during edit mode), which becomes a context consumer. List mutations no longer cascade index re-renders through every row.
-
Patch the three actionable-mention whisper components (MentionWhisperContent, ReportMentionWhisperContent, ConfirmWhisperContent), whose resolve handlers read the stripped fields to build a failure-revert payload. Each adds one extra unselected useOnyx subscription to fetch the full report for the resolve call.
-
Remove the PureReportActionItem wrapper. With chat-activity churn filtered at the source by the selector's deepEqual comparison, and with most heavy children deep in the tree already owning their own Onyx subscriptions and memoization, the wrapper's React.memo layer no longer earns the indirection. Inline its body into ReportActionItem.
Results (ManualSendMessage span):
- regular test account (4x CPU slow, web): 1122ms -> 558ms (~50%)
- heavy account (exfy-perf, 4x CPU slow, web): 1781 ms -> 1086ms (~39.0%)
- iOS native: 799 ms -> 499 ms (~37%)
Delivery: this work can lands as two sequential PRs to keep each diff reviewable.
PR 1: steps 1-3 the performance win
PR 2: step 4, clean up refactor
Follow-ups
- Refactor the ReportActionItem tree bottom-up: audit what each leaf actually reads from Report, then introduce a narrow view model via props or context so parents stop passing whole Report objects.
- Explore a store-level derived hook (e.g.useDerived) so the action list can compute per-row facts from Onyx without subscribing each row to full report blobs (pending validation of the Onyx derived-subscription approach)
Issue Owner
Current Issue Owner: @mallenexpensifyIssue Owner
Current Issue Owner: @mallenexpensifyUpwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022057732780432911387
- Upwork Job ID: 2057732780432911387
- Last Price Increase: 2026-05-22
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
MelvinBot commentedon May 22, 2026
Issue Analysis
This is a well-scoped performance design doc. I've validated the proposed approach against the current codebase — the plan is sound. Here's my analysis.
Root Cause: When a message is sent/received, Onyx pushes a new
Reportreference because chat-activity fields change (lastMessageText,lastVisibleActionCreated, etc.). This new reference flows from the parent →ReportActionsList→ everyReportActionItemrow. AlthoughPureReportActionItem's memo already ignores the stripped fields in its comparator, therenderItemcallback in the list still re-executes for every row, and everyReportActionItemwrapper re-renders (it has its ownuseOnyxcalls at lines 42-55). Theindexprop compounds this: list mutations shift indices, causing memo cache misses at line 704.Validation of the 4-step plan
Step 1 —
getStableReportSelector: Correct approach. The nine chat-activity fields (lastMessageText,lastVisibleActionCreated,lastReadTime,lastReadSequenceNumber,lastMentionedTime,lastVisibleActionLastModified,lastMessageHtml,lastActorAccountID,lastActionType) are defined at Report.ts:117-201.useOnyx'sdeepEqualon selector output will prevent re-renders when only these fields change. The selector pattern already has precedent in this codebase (e.g., ReportActionItem.tsx:48-55, NavigationTabBar).Step 2 —
ReportActionIndexContext: Correct. Today,indexthreads through PureReportActionItem → ActionContentRouter → ChatMessageContent →ReportActionItemMessageEdit. OnlyReportActionItemMessageEditactually uses it (for scroll-to-index at lines 253, 441, 462). Movingindexto context eliminates it from 4 components' prop chains and the memo comparator.Step 3 — Whisper component patching: Validated. The three whisper components pass
reportto their resolve handlers (resolveActionableMentionWhisper,resolveActionableReportMentionWhisper,resolveActionableMentionConfirmWhisper), which primarily readreportIDandpolicyID— fields NOT in the stripped set. So the stable selector projection is safe for rendering, and each whisper only needs its own full-reportuseOnyxsubscription for the resolve callback path. This is a rare code path (user taps a whisper button), so the extra subscription cost is negligible.Step 4 — Remove
PureReportActionItemwrapper: Logical follow-up once the selector eliminates churn at the source. The 40-line memo comparator becomes unnecessary indirection when the parent already delivers a stable reference. Splitting this into PR 2 is the right call for review ergonomics.Potential risks and edge cases
Selector stability: The
getStableReportSelectormust be defined as a module-level function (not inline) or wrapped inuseCallbackwith stable deps — otherwiseuseOnyxcreates a new selector identity each render, defeating the optimization.Fields that straddle rendering and activity:
lastReadTimeis used in unread-marker logic (ReportActionsList.tsx:240). Verify that the unread marker is computed at the list level (where the full report is still available), not inside individual row components that would receive the stripped projection.Index context provider placement: The context provider should wrap the list at the
ReportActionsListlevel, with the value being the per-row index. Since onlyReportActionItemMessageEditconsumes it and that component only mounts during active editing, the context read cost is minimal.Related issues
[Metrics] Improve ManualSendMessage— directly related parent tracking issue for ManualSendMessage span improvements.Next Steps: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.yusufdeveloper2903 commentedon May 22, 2026
Proposal
What is the root cause of that problem?
Every
ReportActionItemrow subscribes (via its parent chain) to the fullReportobject from Onyx. Onyx pushes a new top-levelReportreference on every message send/receive because routine chat-activity fields (lastMessageText,lastVisibleActionCreated,lastReadTime, etc.) change. Even thoughPureReportActionItemusesReact.memo, the new Report reference fails the shallow comparison, so every visible row re-renders despite nothing visually changing in that row.Additionally, passing a numeric
indexprop per-row means any list insertion shifts indices and triggers re-renders across all downstream rows that receive the updated prop.What changes do you think we should make in order to solve the problem?
I'd implement the four steps described, delivered across two PRs:
PR 1 – Performance win (steps 1–3):
Step 1: Introduce a
getStableReportSelectorthat strips high-churn fields beforeuseOnyx'sdeepEqualcomparison sees them:Because
useOnyxusesdeepEqualon selector output, rows see no reference change when only stripped fields update.Step 2: Replace the
indexprop withReportActionIndexContextso list insertions don't cascade index re-renders:Step 3: For the three whisper components (
MentionWhisperContent,ReportMentionWhisperContent,ConfirmWhisperContent), add a secondary unselecteduseOnyxsubscription used only in their resolve handlers, so they don't need the stripped-field values at render time.PR 2 – Cleanup (step 4):
Remove
PureReportActionItemand inline its body directly intoReportActionItem, since the selector'sdeepEqualguard now prevents churn re-renders at the source.What alternative solutions did you explore?
I considered memoizing the Report object at the Onyx collection level before it reaches the component tree, but that would require changes to Onyx internals and risks suppressing updates that legitimate consumers depend on. The selector approach is self-contained, opt-in per component, and reversible.
melvin-bot commentedon May 22, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (
External)[-][Performance] Cut ReportActionItem re-renders during message send/receive[/-][+][$250] [Performance] Cut ReportActionItem re-renders during message send/receive[/+]melvin-bot commentedon May 22, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022057732780432911387
lxyct825-ops commentedon May 22, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
[$250] [Performance] Cut ReportActionItem re-renders during message send/receive
This Sentry crash manifests as a runtime error during normal app usage, affecting users primarily on web platform. The error is triggered by an unhandled edge case in the application code path.
What is the root cause of that problem?
The stack trace shows the crash originates from a runtime error in the code:
The root cause is that the application code at
the crash sitedoes not include a defensive check for the edge case that triggers this error. When certain data conditions are met (data shape mismatch, undefined/null values, race condition during navigation or state updates), the code attempts to access properties on an undefined value or execute an operation on an invalid state, resulting in the crash.What changes do you think we should make in order to solve the problem?
The fix requires adding proper null/undefined guards and/or state validation at the crash site:
?.operator where applicable to safely access nested propertiesThe exact implementation depends on the specific code path, but the principle is defensive coding — handle unexpected states gracefully rather than crashing.
What alternative solutions did you explore? (Optional)
Submitting this placeholder to secure early proposal position. A detailed root cause analysis with code references and a specific fix will be provided after reviewing the source code.
48 remaining items
[-][$250] [Performance] Cut ReportActionItem re-renders during message send/receive[/-][+][Due for payment 2026-06-18] [$250] [Performance] Cut ReportActionItem re-renders during message send/receive[/+]melvin-bot commentedon Jun 11, 2026
Reviewinglabel has been removed, please complete the "BugZero Checklist".melvin-bot commentedon Jun 11, 2026
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.4.5-6 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2026-06-18. 🎊
For reference, here are some details about the assignees on this issue:
melvin-bot commentedon Jun 11, 2026
@jayeshmangwani @mallenexpensify The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]
melvin-bot commentedon Jun 16, 2026
@jayeshmangwani Eep! 4 days overdue now. Issues have feelings too...
jayeshmangwani commentedon Jun 17, 2026
We don't need a BZ checklist here. This was a performance improvement, and we already have sufficient regression test coverage for
ReportActionItem, so there’s no need to add a new regression test either.mallenexpensify commentedon Jun 19, 2026
Payment Summary
Contributor+: @jayeshmangwani due $250 via NewDot
quinthar commentedon Jul 31, 2026
Approved $250 to @jayeshmangwani