Skip to content

[No QA] perf: Build the room participant set once per mention lookup - #107366

Merged
roryabraham merged 6 commits into
Expensify:mainfrom
KJ21-ENG:KJ21-ENG/perf-mention-participant-lookup
Nov 21, 2026
Merged

roryabraham merged 6 commits into
Expensify:mainfrom
KJ21-ENG:KJ21-ENG/perf-mention-participant-lookup

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

The composer ranks room participants first in the @ mention suggestions. To do that, getUserMentionOptions called isReportParticipant once for every personal detail, and each call built a new array from report.participants and searched it. One suggestion refresh therefore cost (personal details) × (room participants), on every key typed in a mention.

This PR builds the participant set once per refresh with a new getReportParticipantAccountIDSet helper (participants, owner and manager) and checks each personal detail against it. isReportParticipant uses the same helper, so the rule stays in one place. The suggestions and their order do not change.

Jest benchmark (tests/perf-local/SuggestionMention.perf-local.ts): renders the real SuggestionMention for a workspace room and times one @al lookup. GitHub Actions runner, main and this PR alternated, median of 3 runs (each run measures the lookup 10 times):

Personal details × room participants main this PR
17,000 × 5 75.9 ms 14.0 ms (-82%)
17,000 × 100 97.4 ms 12.1 ms (-88%)
17,000 × 500 194.5 ms 12.3 ms (-94%)
17,000 × 2,000 607.0 ms 12.3 ms (-98%)
5,000 × 5,000 429.1 ms 3.6 ms (-99%)

Chrome, local development build, 4x CPU slowdown, a workspace #admins room, 17,000 personal details and the extra room participants added on the client only. Time from typing @ to the suggestion list showing, main and this PR alternated, median of 3 runs:

Room participants main this PR
500 1,624 ms 555 ms (-66%)
2,000 5,037 ms 646 ms (-87%)

In the CPU profile at 2,000 participants, isReportParticipant accounts for 12.5 s across the three keys typed (@, a, l) on main, and the new check for 2 ms with this PR.

Fixed Issues

$ #107437
PROPOSAL: #107437

Tests

  1. Open a workspace room or a group chat that has several members, including at least one person who is not a member of the workspace.
  2. Type @ in the composer, then one or two letters that match several people.
  3. Verify that the suggestion list appears, with room participants first, then other workspace members, then everyone else.
  4. Select a suggestion and verify that the mention is inserted.
  5. Open a 1:1 chat, type @ and a letter, and verify that suggestions appear in alphabetical order.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests. Mention suggestions are built from data already on the device.

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

Workspace room: room participants first, then workspace members, then everyone else; selecting a suggestion inserts the mention

01-room-mention.mp4

Group chat: group members first

02-group-mention.mp4

1:1 chat: alphabetical order

03-1on1-mention.mp4

Offline: same suggestions from local data

04-room-offline.mp4
Android: mWeb Chrome

Workspace room: room participants first, then workspace members, then everyone else; selecting a suggestion inserts the mention

01-room-mention.mp4

Group chat: group members first

02-group-mention.mp4

Offline: same suggestions from local data

03-room-offline.mp4
iOS: Native

Workspace room: room participants first, then workspace members, then everyone else; selecting a suggestion inserts the mention

01-room-mention.mp4

Group chat: group members first

02-group-mention.mp4

1:1 chat: alphabetical order

03-1on1-mention.mp4

Offline: same suggestions from local data

04-room-offline.mp4
iOS: mWeb Safari

Workspace room: room participants first, then workspace members, then everyone else; selecting a suggestion inserts the mention

01-room-mention.mp4

Group chat: group members first

02-group-mention.mp4
MacOS: Chrome / Safari

Chrome, local development build, 4x CPU slowdown, the workspace #admins room with 17,000 personal details and 2,000 room participants. Each clip types @, a and l in the composer.

Before (main): the suggestion list appears about 5 s after @ is typed.

A-p2000-t4-chatpane.mp4

After (this PR): the suggestion list appears about 0.6 s after @ is typed.

B-p2000-t4-chatpane.mp4

After merging the latest main: workspace room (weighted order and selecting a suggestion), 1:1 chat (alphabetical order) and the same room offline.

desktop-room-dm-offline.mp4

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

Before and after recordings: Chrome, local development build, 4x CPU slowdown, the workspace #admins room with 17,000 personal details and 2,000 room participants. Each clip types @, a and l in the composer without sending.

Before (main): the suggestion list appears about 5 s after @ is typed.

A-p2000-t4-chatpane.mp4

After (this PR): the suggestion list appears about 0.6 s after @ is typed.

B-p2000-t4-chatpane.mp4

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

Side-by-side comparison for accurate comparison.

side-by-side-p2000-t4.mp4

@KJ21-ENG
KJ21-ENG marked this pull request as ready for review November 20, 2026 07:48
@KJ21-ENG
KJ21-ENG requested review from a team as code owners November 20, 2026 07:48
@expensify-chore-bot
expensify-chore-bot Bot requested review from lorretheboy and removed request for a team November 20, 2026 07:49
@expensify-chore-bot

Copy link
Copy Markdown

@lorretheboy Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@expensify-chore-bot
expensify-chore-bot Bot requested review from heyjennahay and removed request for a team November 20, 2026 07:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T08:01:03.476324Z a102981 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lorretheboy

lorretheboy commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@lorretheboy

Copy link
Copy Markdown
Contributor

Reviewing...

@lorretheboy

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

MelvinBot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Web test steps verification results: ⚠️ partial

Testing was blocked by unavailable fixtures on dev NewDot web. No regression was confirmed.
Fresh account Inbox showing only Concierge

Step Status
1. Open a multi-member room/groupOnly Concierge was available; the required fixture was missing.
Fresh account Inbox showing only Concierge
⚠️
2. Type @ and matching lettersMultiple matching contacts were unavailable.
⚠️
3. Verify participant/workspace/other orderingRequired membership fixtures were unavailable.
⚠️
4. Select and insert a mentionNot tested after the fixture blocker.
⚠️
5. Verify alphabetical 1:1 suggestionsNo suitable multiple-contact fixture was available.
⚠️
6. Repeat offlineFixtures were unavailable; permitted browser controls also lacked offline switching.
⚠️
7. Check JS console errorsConsole inspection was unavailable through permitted browser controls.
⚠️

Code review: No actionable correctness issues found. The participant Set is built outside the per-contact callback, and the helper preserves owner, manager, and hidden-participant membership.

Local validation: 1,771 unit tests passed, plus all 5 benchmark scenarios. Benchmark timings are not treated as validated performance measurements because plain Jest emitted a Reassure configuration warning. Browser behavior and the reported speedup remain independently unverified.


view run · view recording

@lorretheboy

Copy link
Copy Markdown
Contributor

@KJ21-ENG I think we don't need QA for this PR as it is purely util function refactoring while we have already included sufficient test/perf test. Please add [No QA] prefix in PR title

@lorretheboy lorretheboy 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.

🎀👀🎀 C+ reviewed

@melvin-bot
melvin-bot Bot requested a review from roryabraham November 20, 2026 16:54
@KJ21-ENG KJ21-ENG changed the title perf: Build the room participant set once per mention lookup [No QA] perf: Build the room participant set once per mention lookup Nov 20, 2026
@roryabraham
roryabraham merged commit 9ab32e1 into Expensify:main Nov 21, 2026
44 of 48 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.5.53-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR only optimizes mention suggestion performance without changing suggestions, their order, or the user workflow, so existing guidance remains accurate.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/arosiclair in version: 9.5.53-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants