Skip to content

Commit 65c32e5

Browse files
committed
Merge branch 'perf/lhn-baselines' into perf/lhn-sort-cache
2 parents aa9083d + 9b4116e commit 65c32e5

5 files changed

Lines changed: 38 additions & 78 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ function setSortedReportActionsCacheMaxSize(newSize: number): void {
672672
sortedReportActionsCacheMaxSize = newSize;
673673
}
674674

675-
// Immediately evict if current caches are above the new limit.
676675
evictOldestCacheEntries(sortedReportActionsCacheAscending);
677676
evictOldestCacheEntries(sortedReportActionsCacheDescending);
678677
}

src/libs/SidebarUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ function getReportsToDisplayInLHN(
274274
) {
275275
const isInFocusMode = priorityMode === CONST.PRIORITY_MODE.GSD;
276276
const allReportsDictValues = reports ?? {};
277-
// Adjust the size of the sorted report actions cache to roughly match
278-
// the current number of reports, while still respecting the global cap
279-
// inside ReportActionsUtils to guard against excessive memory usage.
277+
280278
setSortedReportActionsCacheMaxSize(Object.keys(allReportsDictValues).length);
281279
const reportsToDisplay: ReportsToDisplayInLHN = {};
282280

tests/perf-test/ReportActionsUtils.perf-test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import {getLastClosedReportAction} from '@selectors/ReportAction';
22
import Onyx from 'react-native-onyx';
33
import {measureFunction} from 'reassure';
4-
import {getLastVisibleAction, getLastVisibleMessage, getMostRecentIOURequestActionID, getSortedReportActionsForDisplay} from '@libs/ReportActionsUtils';
4+
import {
5+
getLastVisibleAction,
6+
getLastVisibleMessage,
7+
getMostRecentIOURequestActionID,
8+
getSortedReportActions,
9+
getSortedReportActionsForDisplay,
10+
} from '@libs/ReportActionsUtils';
511
import CONST from '@src/CONST';
612
import ONYXKEYS from '@src/ONYXKEYS';
713
import type {ReportActions} from '@src/types/onyx/ReportAction';
@@ -35,6 +41,7 @@ const reportActions = createCollection<ReportAction>(
3541
);
3642

3743
const reportId = '1';
44+
const ACTIONS_COUNT_CACHE = 100;
3845

3946
describe('ReportActionsUtils', () => {
4047
beforeAll(() => {
@@ -140,4 +147,33 @@ describe('ReportActionsUtils', () => {
140147
await waitForBatchedUpdates();
141148
await measureFunction(() => getLastClosedReportAction(reportActions));
142149
});
150+
151+
test('[ReportActionsUtils] getSortedReportActions cache hit performance', async () => {
152+
const reportActionsForCache = createCollection<ReportAction>(
153+
(item) => `${item.reportActionID}`,
154+
(index) => createRandomReportAction(index),
155+
ACTIONS_COUNT_CACHE,
156+
);
157+
const actionsArray = Object.values(reportActionsForCache);
158+
159+
await measureFunction(() => getSortedReportActions(actionsArray, true), {
160+
runs: 20,
161+
warmupRuns: 5,
162+
});
163+
});
164+
165+
test('[ReportActionsUtils] getSortedReportActions cache hit with different array references', async () => {
166+
const reportActionsForCache = createCollection<ReportAction>(
167+
(item) => `${item.reportActionID}`,
168+
(index) => createRandomReportAction(index),
169+
ACTIONS_COUNT_CACHE,
170+
);
171+
const actionsArray = Object.values(reportActionsForCache);
172+
const newArrayRef = [...actionsArray];
173+
174+
await measureFunction(() => getSortedReportActions(newArrayRef, true), {
175+
runs: 20,
176+
warmupRuns: 5,
177+
});
178+
});
143179
});

tests/perf-test/ReportActionsUtilsCache.perf-test.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/perf-test/SidebarUtils.perf-test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -384,26 +384,6 @@ describe('SidebarUtils', () => {
384384
});
385385
});
386386

387-
test('[SidebarUtils LHN] scaling – 2000 reports', async () => {
388-
const dataSet = createLHNReportsWithActions(2000);
389-
await Onyx.multiSet({
390-
...dataSet.reports,
391-
...dataSet.reportActions,
392-
...dataSet.reportNameValuePairs,
393-
} as Parameters<typeof Onyx.multiSet>[0]);
394-
await waitForBatchedUpdates();
395-
396-
await measureFunction(() => {
397-
for (const reportKey of Object.keys(dataSet.reports)) {
398-
const reportID = reportKey.replace(ONYXKEYS.COLLECTION.REPORT, '');
399-
const actions = dataSet.reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
400-
if (actions) {
401-
getSortedReportActionsForDisplay(actions, true);
402-
}
403-
}
404-
});
405-
}, 600000);
406-
407387
test('[SidebarUtils LHN] cache usage verification – allSortedReportActions cache', async () => {
408388
await waitForBatchedUpdates();
409389
await new Promise((resolve) => {

0 commit comments

Comments
 (0)