Repository navigation
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@abzokhattab 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] |
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
|
Very nice improvement 🚀 ,, clean diagnosis and exactly the right fix. I reproduced the before/after in a standalone Node script: I copied both implementations verbatim, built a synthetic
Both paths matched the same 220 rows, so the filter output is unchanged. Benchmark scriptfunction isPolicyApproverOld(policy, employeeLogin) {
if (policy?.approver === employeeLogin) {
return true;
}
return Object.values(policy?.employeeList ?? {}).some(
(employee) => employee?.submitsTo === employeeLogin || employee?.forwardsTo === employeeLogin || employee?.overLimitForwardsTo === employeeLogin,
);
}
function getPolicyApproverLogins(policy) {
const approverLogins = new Set();
if (policy?.approver) {
approverLogins.add(policy.approver);
}
for (const employee of Object.values(policy?.employeeList ?? {})) {
if (employee?.submitsTo) {
approverLogins.add(employee.submitsTo);
}
if (employee?.forwardsTo) {
approverLogins.add(employee.forwardsTo);
}
if (employee?.overLimitForwardsTo) {
approverLogins.add(employee.overLimitForwardsTo);
}
}
return approverLogins;
}
function buildPolicy(memberCount) {
const employeeList = {};
const rows = [];
for (let i = 0; i < memberCount; i++) {
const email = `member${i}@example.com`;
employeeList[email] = {email, submitsTo: `member${Math.floor(i / 100) * 100}@example.com`, forwardsTo: '', overLimitForwardsTo: ''};
rows.push({login: email});
}
return {policy: {approver: 'member0@example.com', employeeList}, rows};
}
for (const memberCount of [1000, 5000, 22000]) {
const {policy, rows} = buildPolicy(memberCount);
let start = performance.now();
let oldMatches = 0;
for (const row of rows) {
if (isPolicyApproverOld(policy, row.login)) {
oldMatches++;
}
}
const oldMs = performance.now() - start;
start = performance.now();
const approverLogins = getPolicyApproverLogins(policy);
let newMatches = 0;
for (const row of rows) {
if (approverLogins.has(row.login)) {
newMatches++;
}
}
const newMs = performance.now() - start;
console.log(`${memberCount} members | main: ${oldMs.toFixed(0)} ms | PR: ${newMs.toFixed(2)} ms | matches ${oldMatches}/${newMatches}`);
}I noticed the same O(N²) is still live on this page in the remove flow — the per-login |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppScreen.Recording.2026-07-29.at.16.37.25.moviOS: mWeb SafariScreen.Recording.2026-07-29.at.16.38.41.movMacOS: Chrome / SafariScreen.Recording.2026-07-29.at.16.35.20.mov |
abzokhattab
left a comment
There was a problem hiding this comment.
LGTM, great perf improvment 🚀🚀
|
✋ 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.46-0 🚀
|
|
🤖 I reviewed the changes in this PR against Expensify's help site content under No help site changes are required. This is a performance-only change: it precomputes the set of approver logins once ( Since no docs update is needed, I did not create a help site draft PR, apply the @TMisiukiewicz, if you believe this change does affect documented behavior, let me know what's user-facing and I'll draft the help site update. |
|
🚀 Deployed to production by https://github.com/marcaaron in version: 9.4.46-10 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
On large workspaces (~22k members), selecting any filter on the Workspace Members page froze the app for minutes. The filter called
isPolicyApproveronce per row, and each of those calls scanned the entire employee list to check if that row's login was an approver — O(N) work per row, O(N²) overall (~484M operations at 22k members).This PR precomputes the set of approver logins once per render via a new
getPolicyApproverLogins(policy)helper inPolicyUtils.ts(O(N), single pass over the employee list), then each row does an O(1)Set.has(login)lookup instead of re-scanning the list. Turns the multi-minute freeze into an instant filter.Fixed Issues
$ #97332
PROPOSAL:
Tests
Offline tests
N/A
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