Repository navigation
Optimize hasEnabledTags used by MoneyRequestView - #101862
Conversation
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
mountiny
left a comment
There was a problem hiding this comment.
Looks like good refactoring
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
@aimane-chnaif 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] |
| .filter((tag) => tag?.tags) | ||
| .map(({tags}) => Object.values(tags)) | ||
| .flat(); | ||
| for (const tagList of policyTagList) { |
There was a problem hiding this comment.
function hasEnabledTags(policyTagList: Array<PolicyTagLists[keyof PolicyTagLists]>) {
return policyTagList.some((tagList) => Object.values(tagList?.tags ?? {}).some(isOptionEnabled));
}
Can we simplify code like this? Or doesn't help with performance optimization?
There was a problem hiding this comment.
Object.values() creates the full tag array for a list. So on a policy with a few thousand tags we allocate the whole array even when the very first tag answers the question. The loop allocates nothing and bails on the first hit, so the performance is better here
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppios.moviOS: mWeb SafariMacOS: Chrome / Safariweb.mov |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 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! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.92-0 🚀
|
|
🤖 No help site changes required. I did not create a docs PR. This PR is a pure performance refactor with no user-facing behavior change, so nothing under WhyAll four changed files are internal:
There is no new feature, no renamed or relocated setting, no changed label or button, and no change to when the Tag row or the "tags disabled" alert appears. The help site documents what users see and do, and none of that moved. Note: I could not verify this in a browser — browser control was unavailable for this run — so this assessment is from the diff and code alone. That's sufficient here, since the change is a behavior-preserving refactor rather than a UI change. @TMisiukiewicz — since no docs PR was needed, there's nothing to review or mark |
|
🚀 Deployed to production by https://github.com/lakchote in version: 9.4.92-8 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Opening a report could spend ~100ms just checking whether a policy has any enabled tags. Two problems caused this:
hasEnabledTagsbuilt three throwaway arrays of every tag in the policy (filter+map(Object.values)+flat), plus another insidehasEnabledOptions, before answering a yes/no question. Now it walks the tag lists with plain loops and stops at the first enabled, non-deleted tag, with no allocations. The answer is the same as before.MoneyRequestViewran this check twice per render (once to decide whether to show the tag row, once for the "tags disabled" alert). It now computes the result once per render and reuses it.Fixed Issues
$ #101863
PROPOSAL:
Tests
Offline tests
Same as tests, but with the network connection turned off. Verify the app behaves the same and no errors appear.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, 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