Skip to content

[Metrics] Investigate remaining ~1-2s ManualSendMessage spans #95584

Closed
2 of 2 issues completed
Closed

Description

@cristipaval

Context

After cancelling the skeleton-blocked spans, we still see many ManualSendMessage spans in the ~1-2s range. This issue tracks the investigation into which real scenarios are the slowest, so we can target them next.

Ideas to check

1. Concierge chats

Look closer at Concierge chats, or chats that include Concierge responses. Some sessions took longer when the Concierge right panel was used to send messages, or when the user chatted with Concierge directly. Worth checking Concierge-related chats on both mobile and web.

2. Big account, big report, single expense

Found a user who sent 11 messages, each 2-3s. Worth checking a large account that opens "Spend", then opens a big report with many expenses, then opens a single expense from that list (right side panel) and sends a message there. Many components re-render because of the report + report_action updates.

3. Add attributes for the send path

Add attributes that tell us from which path a message was sent. So far the focus was mostly on chat from the inbox. Knowing the path would help us spot the worst scenario faster, and likely unblocks ideas 1 and 2.

Parent

Part of #77176

Issue OwnerCurrent Issue Owner: @LukasMod

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. self-assigned this
    on Jul 8, 2026
  2. LukasMod commented on Jul 9, 2026

    @LukasMod
    Contributor

    Part3:

    I opened PR #95666, which adds a new send_message_source attribute on the ManualSendMessage. Goal is to see where people send messages, so we can tell which paths are the send-message bottlenecks instead of looking at one blended number.

    To track it, I added a table grouped by this attribute to the Sentry dashboard, giving us a distribution per path (with some variants). With it, we will be able drill into a specific user and see whether certain paths are consistently slower


    Next, I plan to investigate the 2. Big account, big report, single expense scenario and look for avoidable rerenders.

  3. cristipaval commented on Jul 9, 2026

    @cristipaval
    ContributorAuthor

    Nice work on the send_message_source attribute and the dashboard table, this will help us a lot to see which paths are the real bottlenecks.

    One small thing: I moved this attribute work into its own issue #95709 and repointed PR #95666 there, so the PR closes something scoped. Let's keep this issue (#95584) as the tracking one for the whole investigation.

    +1 on going after the 2. Big account, big report, single expense scenario next. The many re-renders from the report + report_action updates look like the main cost there.

  4. LukasMod commented on Jul 10, 2026

    @LukasMod
    Contributor

    When a user opens the RHP for a specific transaction and sends a message, the heavy lists rerenders.

    The rerenders:

    1. Spend results (Search)
    2. RHP with transactions and chat, and finally
    3. currently opened report

    ... so its quite a lot of elements, and its only my small test account for sending messages

    Image

    I'm still experimenting, but even after enabling the React Compiler in MoneyRequestReportTransactionList and stabilizing a few things around it, I haven't seen a consistent improvement so far. Many utilities, hooks, and components rely on the full report or reportActions objects, or on related derived values, so they still have to re-render. I'm trying to pass primitive values instead of whole objects where possible and split some logic to make it more suitable for the React Compiler.

    I'll continue investigating this next week.

  5. LukasMod commented on Jul 13, 2026

    @LukasMod
    Contributor

    Work in progress, sharing where I've landed so far.

    I ran a few experiments. First I measured the span in a scenario where the heavy lists underneath are absent (hidden via a dev toggle), and it came out almost 50% faster. So that's effectively the ceiling for this re-render issue.

    From there I tried to stabilize the expensive listing as much as possible using an isFocused-gated freeze, React Compiler, and manual memo where the compiler bails. With several small moves stacked together I got roughly -20% to -25% (stabilizing only MoneyRequestReport now)

    Next I'll turn these PoC into a plan with achievable, shippable steps, but I need to to some additional testing.

    Metric Baseline Ceiling (heavy lists hidden) Current (stabilizing MoneyRequestReport)
    Mean 280.5 ms 159.2 ms 209.8 ms (-25%)
    • Baseline = report view renders normally, no optimization.
    • Ceiling (heavy lists hidden) = MoneyRequestReportTransactionList and SearchPageWide removed via the dev toggle. Not a shippable implementation (the lists are simply absent).
    • Current = the focus-gated freeze plus memo() boundaries, with the lists still fully rendered.

    PoC (middle section memoized)

    Image
  6. LukasMod commented on Jul 14, 2026

    @LukasMod
    Contributor

    The solution seems to be working, but it feels a bit hacky and more like a workaround than a fix for the root cause of the problem - the Onyx subscription call. I'm investigating the subscribed option in the internal useOnyx hook. It would allow us to pause subscriptions on unfocused screens. So far, the initial results look promising. I'm going to do some more testing around this idea, and if it proves to be safe, I'll prepare a proposal for a new Onyx feature:

    WIP PoC:
    Draft EApp PR: #95952
    Draft Onyx PR: Expensify/react-native-onyx#808

    Summary

    Metric Baseline fix % Change
    Samples (n) 27 31 —
    Mean 315.0 199.5 −36.7%
    Std dev 95.9 45.8 −52.2%
    p75 386 238 −38.3%
  7. LukasMod commented on Jul 15, 2026

    @LukasMod
    Contributor

    Update: Work in progress. I'm testing different ideas and incorporating some initial feedback before creating the proposal.

  8. cristipaval commented on Jul 17, 2026

    @cristipaval
    ContributorAuthor

    Thanks for the detailed updates @LukasMod, this is great progress. The Onyx subscribed approach sounds much cleaner than the freeze workaround, and the numbers are promising (−36.7% mean is a big win).

    Pausing subscriptions on unfocused screens feels like a good direction for the root cause. Tag me when you post the proposal, and let me know how I can help move it forward.

  9. LukasMod commented on Jul 17, 2026

    @LukasMod
    Contributor

    @cristipaval
    Sure! I've shared the proposal internally and I'm waiting on feedback now.

    The potential gains look great. Today I experimented further with more aggressive changes and stabilized the list in Spend and, in a heavy scenario, spans dropped by almost 70% 🔥, so there's a lot to gain here, though it also involves a fair number of changes. If this gets approved, I think we should roll it out gradually so we can catch any regressions early.
    The feature only pays off once the lists are stable through their other render drivers too, and that adds a bunch of conditions / isFocused checks along the way, together with the standard memoization work. Also, for the first use, we should probably do an AdHoc build and have someone else test it too.

    I will update when I get some feedback on Monday 👍

  10. LukasMod commented on Jul 20, 2026

    @LukasMod
    Contributor

    Update:

    • Proposal is after first round of internal feedback. I do some changes to proposal and simplify this feature usage to per screen instead per component/hook. I'm adding new benchmarks and tests, preparing for second round

    New draft PoC: #96471
    Based by the same onyx change as before: Expensify/react-native-onyx#808

  11. LukasMod commented on Jul 21, 2026

    @LukasMod
    Contributor

    Update:

    • I shared the proposal internally again. Idea is rewritten, it's now not throttling but freezing when not subscribed. It also showed an improvement in the openReport metric for the screen touched in the PoC (web only, but around 30%). I'm waiting for feedback on this form my team
    • Meanwhile, I need to verify some logic conditions that could potentially cause regressions if the proposal is accepted, or at least estimate whether they are truly low-risk issues that can be handled without sacrificing the solution

    Draft PoC: #96471
    Onyx subscribed: Expensify/react-native-onyx#808

  12. LukasMod commented on Jul 27, 2026

    @LukasMod
    Contributor

    Update:

    React-navigation 8 is in alpha now but with current proposal there are trades off and additional code complexity. If this will work, focus logic would live where it supposed to - in navigation and not in onyx-around logic

  13. 51 remaining items

  14. cristipaval commented on Oct 13, 2026

    @cristipaval
    ContributorAuthor

    Thanks @LukasMod! I created this subissue to track the report hierarchy subscription work and linked your draft PR there. The approach makes sense to me.

  15. LukasMod commented on Oct 16, 2026

    @LukasMod
    Contributor

    Two new findings on the Concierge topic while investigating this issue:

    1. We lose the span for the first message a user sends in the Concierge side panel, because the switch to the new thread cancels it. I prepared a fix so we keep this data: [NoQA] Keep first Concierge send span alive across the thread switch #104240. Probably related to Show generated thread title #99317
    Image
    1. I prepared a fix that saves some re-renders when the user writes to Concierge in the side panel, by using selectors: Read the Concierge chat on press instead of subscribing to it in render #104242
  16. LukasMod commented on Oct 20, 2026

    @LukasMod
    Contributor

    @cristipaval
    Here’s the PR addressing the issue with cancelled Concierge spans: #104240 (number 1 from my previous comment and screenshot).

    I’m continuing to investigate the second PR to find more opportunities to improve Concierge chat (1 bullet from this issue). I’ve found a few potential leads, but nothing promising yet.

  17. Julesssss commented on Oct 21, 2026

    @Julesssss
    Contributor

    Sounds good @LukasMod, just to let you know Cristi is on parental leave and I will be ooo starting next week. But please keep the updates and investigations coming.

  18. LukasMod commented on Oct 21, 2026

    @LukasMod
    Contributor

    @Julesssss Thanks! Could you create a separate tracking issue for #104240, or should I link it to this issue instead? I’m not sure which issue would be the best fit, as it’s a fairly separate issue but still related to messages

  19. Julesssss commented on Oct 21, 2026

    @Julesssss
    Contributor

    Could you create a separate tracking issue

    Yeah sure, sub-issue here.

  20. LukasMod commented on Nov 2, 2026

    @LukasMod
    Contributor

    I prepared PR #104242 for concierge problem mentioned in this issue. PR switch the Concierge chat report (and a few rarely changing keys) from useOnyx subscription in render to Onyx.get / Onyx.multiGet when they need it (press handlers). Below you can find some benchmarks from web and iOS. I will prepare all test videos and move to review

    1. Sending a message from the Concierge side panel (web) - ManualSendMessageVisible

    The side panel sits at the Concierge root with another screen in the central pane

    Central pane behind the side panel before after change
    Workspace chat with 10 report previews 1614 ms 1242 ms -23.0%
    Self DM with tracked expenses 1441 ms 1355 ms -6.0%
    Spend > Reports 2144 ms 2052 ms -4.3%
    Expense report with header Pay 1663 ms 1617 ms -2.8%

    2. Re-renders per write to the Concierge chat report

    I counted React fibers that re-rendered in the central pane and the time React spent committing.

    Screen Web fibers before after change Web commit ms before after change
    Self DM 756 155 -79% 207 97 -53%
    Workspace chat 1754 212 -88% 335 98 -71%
    Spend > Reports 2187 842 -61% 898 588 -35%
    Expense report 1093 561 -49% 255 154 -40%
    Screen iOS fibers before after change iOS commit ms before after change
    Self DM 1663 1158 -30% 474 268 -43%
    Workspace chat 2427 1310 -46% 807 399 -51%
    Spend > Reports 1725 1275 -26% 462 295 -36%
    Expense report 1731 1545 -11% 470 331 -30%

    These components no longer re-render on a Concierge write: the report actions list and every ChatTransactionPreview in the self DM; every MoneyRequestReportPreview and its Pay SettlementButton in the workspace chat; every ExpenseReportListItem row, its ActionCell and PayActionCell in Spend > Reports; the report actions list and the header SettlementButton on the expense report.

    Profiler example (web, Workspace chat):

    Image

    3. Press handler latency (regression tests)

    I measured from the press to the first thing that matters: Navigation.navigate for navigation flows, the first API.write for Pay, and the report becoming visible where one opens.

    Flow Platform Metric before after change 95% CI user visible
    Spend > Reports row View web (30 vs 30) press to navigate 22 ms 24 ms +2 ms [-0, +3] none: press to report visible 971 to 969 ms, [-27, +30]
    Header Pay, "Mark as paid" web (7 vs 8) press to PayMoneyRequest write 203 ms 251 ms +48 ms (+24%) [+30, +62] none: popover closes at the same time, API response +271 ms [-224, +632]
    Header Pay, "Mark as paid" iOS (8 vs 8) press to PayMoneyRequest write 375 ms 414 ms +40 ms (+10%) [+22, +56] none: API response +187 ms [-119, +355]
    Explain link web (7 vs 8) press to navigate 3 ms 4 ms +1 ms [-0, +1] none: first API write 394 to 382 ms, [-29, +39]
    Self DM tracked expense preview (thread exists) iOS (12 vs 12) press to navigate 2 ms 2 ms 0 [+0, +2] none: visible 744 to 714 ms, [-196, +206]
    Workspace chat report preview iOS (8 vs 8) press to navigate 4 ms 5 ms 0 [-2, +3] none: visible 1102 to 1166 ms, [-63, +222]

    The awaited reads hit the cache. Pay moved because closing the popover schedules React work (the MODAL subscribers on web, the popover close state on iOS) that now commits before the handler continues rather than after the API write. The same work runs in both variants in a different order. The server request leaves at the same time and the popover disappears at the same moment.

    4. Conclusion

    • Sending from the Concierge side panel is 23% faster with a chat full of report previews behind it. On the other three panes we saw 3-6% faster
    • Every Concierge chat write is cheaper on every screen we measured: 49-88% fewer re-rendered fibers on web, 11-46% on iOS, and 30-71% less commit time
    • No press handler got slower for the user. Navigation flows stay within 2 ms of main. Pay reaches its API write 40 to 48 ms later because a popover-close commit now runs first. The request and the visible close do not change.
  21. added
    Reviewing
    on Nov 2, 2026
  22. LukasMod commented on Nov 5, 2026

    @LukasMod
    Contributor

    @mountiny All the investigations mentioned here have been completed with PRs, and we have a parent issue to track new investigations. I think we can close this one once all the sub-issues are closed as well

  23. mountiny commented on Nov 5, 2026

    @mountiny
    Contributor

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ReviewingWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions