perf: fix O(n²) tag scan in WorkspaceTagsPage#94041
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@neil-marcellini 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] |
|
Created files with a lot of tags workspace-tags-16k.csv |
|
It looks like the web app is frozen after trying to open 16000 child tags for multi-tag 🥲 2026-06-19.15.02.03.mov |
Reviewer Checklist
Screenshots/VideosAndroid: HybridApp2026-06-19.15.16.36.movAndroid: mWeb Chrome2026-06-19.15.16.36.moviOS: HybridApp2026-06-19.15.14.33.moviOS: mWeb Safari2026-06-19.15.10.57.movMacOS: Chrome / SafariUploading Запись экрана — 2026-06-19 в 15.05.37.mov… |
|
Yeah looks like it's a separate thing, we can open a separate issue for this one |
|
Okay then |
mountiny
left a comment
There was a problem hiding this comment.
I will create a follow up for that
|
🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
Tracking the multi-level child tag freeze separately in #94054 — out of scope for this PR. |
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.16-1 🚀
Bundle Size Analysis (Sentry): |
|
🤖 No help site changes required. This PR is a pure performance optimization in The user-facing behavior is unchanged:
Since nothing changed about what the product does — only how fast the Tags page renders — no articles under |
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.4.16-5 🚀
|
Explanation of Change
isDisablingOrDeletingLastEnabledTag(policyTagLists.at(0), [tag])was called for every tag'sshowLockIconprop inside thetagListmap. Internally it callsgetCountOfEnabledTagsOfList, which iterates all tags — O(n) per tag = O(n²) total. With 16k tags this amounts to ~256M filter iterations per render.Fix: compute
enabledTagsCountonce before the map, then derive two O(1) boolean constants —isLastEnabledTagLockedandisLastEnabledTagAndEnabled— and use them inline. Behavior is identical: same lock icon logic, same modal guard.Fixed Issues
$ #94044
$ #93952
PROPOSAL:
Tests
Offline tests
N/A
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-06-19.at.14.19.07.mov