From 1aac233ee62649cfb2f5b38f9639cc9d031f20ba Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Tue, 1 Sep 2026 13:47:48 +0200 Subject: [PATCH 1/7] Add MoneyRequestReportActionsList performance test --- ...oneyRequestReportActionsList.perf-test.tsx | 209 ++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx diff --git a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx new file mode 100644 index 000000000000..dd0fe1a3aa46 --- /dev/null +++ b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx @@ -0,0 +1,209 @@ +import {act, screen} from '@testing-library/react-native'; + +import MoneyRequestReportActionsList from '@components/MoneyRequestReportView/MoneyRequestReportActionsList'; +import OnyxListItemProvider from '@components/OnyxListItemProvider'; +import ScreenWrapperStatusContext from '@components/ScreenWrapper/ScreenWrapperStatusContext'; +import {SearchContextProvider} from '@components/Search/SearchContextProvider'; + +import type Navigation from '@libs/Navigation/Navigation'; +import navigationRef from '@libs/Navigation/navigationRef'; +import {setHasRadio} from '@libs/NetworkState'; + +import {ActionListContext} from '@pages/inbox/ActionListContext'; +import {ReactionListContext} from '@pages/inbox/ReactionListContext'; +import {AttachmentModalContextProvider} from '@pages/media/AttachmentModalScreen/AttachmentModalContext'; + +import initOnyxDerivedValues from '@userActions/OnyxDerived'; + +import ComposeProviders from '@src/components/ComposeProviders'; +import {LocaleContextProvider} from '@src/components/LocaleContextProvider'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type SCREENS from '@src/SCREENS'; +import type {ReportAction, ReportActions, Transaction} from '@src/types/onyx'; + +import {NavigationContainer} from '@react-navigation/native'; +import Onyx from 'react-native-onyx'; +import {measureRenders} from 'reassure'; + +import * as ReportTestUtils from '../utils/ReportTestUtils'; +import * as TestHelper from '../utils/TestHelper'; +import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; +import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; + +const REPORT_ID = '1'; + +jest.mock('@react-navigation/native', () => { + const actualNav = jest.requireActual('@react-navigation/native'); + const SCREENS_MOCK = jest.requireActual<{default: typeof SCREENS}>('@src/SCREENS').default; + return { + ...actualNav, + useRoute: () => ({ + key: 'test-key', + name: SCREENS_MOCK.REPORT, + params: {reportID: '1'}, + }), + useIsFocused: () => true, + }; +}); + +jest.mock('@rnmapbox/maps', () => ({ + default: jest.fn(), + MarkerView: jest.fn(), + setAccessToken: jest.fn(), +})); + +beforeAll(() => { + Onyx.init({ + keys: ONYXKEYS, + evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], + }); + // Register the derived-value computations (e.g. VISIBLE_REPORT_ACTIONS): without this the derived + // keys never update in the test, hiding production re-render behavior from the measurements. + initOnyxDerivedValues(); +}); + +const mockOnLayout = jest.fn(); +// Built via a function so the value isn't an inline literal the context-split lint rule would flag; these are all refs/accessors with no re-render concern. +function buildActionListContextValue() { + return {scrollOffsetRef: {current: 0}, getScrollOffset: () => 0, registerListRef: () => {}, getListRef: () => null}; +} +const actionListContextValue = buildActionListContextValue(); +const mockReactionListContextValue = { + showReactionList: () => {}, + hideReactionList: () => {}, + isActiveReportAction: () => false, +}; +// Transaction items resolve their highlight animation via ScreenWrapper's transition status; the +// perf harness renders no ScreenWrapper, so provide a settled one. +const screenWrapperStatusContextValue = { + didScreenTransitionEnd: true, + isSafeAreaTopPaddingApplied: false, + isSafeAreaBottomPaddingApplied: false, +}; + +const TEST_USER_ACCOUNT_ID = 1; +const TEST_USER_LOGIN = 'test@test.com'; +const POLICY_ID = 'PERF_POLICY_1'; +const TRANSACTIONS_COUNT = 10; + +const signUpWithTestUser = () => { + TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN); +}; + +const sortedReportActions = ReportTestUtils.getMockedSortedReportActions(500); +const reportActions: ReportActions = Object.fromEntries(sortedReportActions.map((action: ReportAction) => [action.reportActionID, action])); +const report = { + ...ReportTestUtils.createMockReport({reportID: REPORT_ID, lastVisibleActionCreated: sortedReportActions.at(0)?.created}), + type: CONST.REPORT.TYPE.EXPENSE, + policyID: POLICY_ID, + total: 10000 * TRANSACTIONS_COUNT, + currency: CONST.CURRENCY.USD, + // Seed the report as already read so mount doesn't fire readNewestAction (a network action whose + // timing would add noise to the measurement). + lastReadTime: sortedReportActions.at(0)?.created, +}; + +const transactions = Array.from({length: TRANSACTIONS_COUNT}, (unused, index) => { + return { + transactionID: `PERF_TXN_${index + 1}`, + reportID: REPORT_ID, + amount: 10000, + currency: CONST.CURRENCY.USD, + merchant: `Merchant ${index + 1}`, + created: '2025-01-01', + status: CONST.TRANSACTION.STATUS.POSTED, + } as Transaction; +}); + +beforeEach(async () => { + // Initialize the network key for OfflineWithFeedback + setHasRadio(true); + wrapOnyxWithWaitForBatchedUpdates(Onyx); + // Pre-seed the locale so LocaleContextProvider's mount effect is a no-op (setLocale early-returns), + // avoiding post-mount Onyx writes that would re-render outside act(). + await act(async () => { + signUpWithTestUser(); + await Onyx.merge(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.DEFAULT); + + // Seed the report under test: the expense report, its 500 actions, its transactions, and a settled loading state. + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, reportActions); + for (const transaction of transactions) { + await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); + } + await Onyx.set(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${REPORT_ID}`, { + isLoadingInitialReportActions: false, + hasOnceLoadedReportActions: true, + isLoadingOlderReportActions: false, + hasLoadingOlderReportActionsError: false, + isLoadingNewerReportActions: false, + hasLoadingNewerReportActionsError: false, + }); + await waitForBatchedUpdates(); + }); +}); + +afterEach(async () => { + // Await the clear so its broadcasts settle in teardown instead of leaking into the next test. + await Onyx.clear(); + await waitForBatchedUpdates(); +}); + +function MoneyRequestReportActionsListWrapper() { + return ( + + + + + + + + + + + + + + ); +} + +test('[MoneyRequestReportActionsList] should render the unified list with 500 reportActions and 10 transactions stored', async () => { + const scenario = async () => { + await screen.findByTestId('money-request-report-actions-list'); + }; + await waitForBatchedUpdates(); + await measureRenders(, {scenario}); +}); + +test('[MoneyRequestReportActionsList] should not re-render when an unrelated report receives new actions', async () => { + const UNRELATED_REPORT_ID = '999'; + const scenario = async () => { + await screen.findByTestId('money-request-report-actions-list'); + // Each merge recomputes the VISIBLE_REPORT_ACTIONS derived value app-wide; the list under test + // must not re-render because its own report's slice is unchanged. + for (let i = 0; i < 5; i++) { + const newAction = ReportTestUtils.getFakeReportAction(600 + i, {actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, created: `2023-09-14 00:00:0${i}.000`}); + // eslint-disable-next-line no-await-in-loop + await act(async () => { + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${UNRELATED_REPORT_ID}`, {[newAction.reportActionID]: newAction}); + await waitForBatchedUpdates(); + }); + } + }; + await waitForBatchedUpdates(); + await measureRenders(, {scenario}); +}); + +test('[MoneyRequestReportActionsList] should re-render the unified list when a new report action arrives', async () => { + const scenario = async () => { + await screen.findByTestId('money-request-report-actions-list'); + const newAction = ReportTestUtils.getFakeReportAction(501, {actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, created: '2023-09-13 00:00:00.000'}); + await act(async () => { + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[newAction.reportActionID]: newAction}); + await waitForBatchedUpdates(); + }); + }; + await waitForBatchedUpdates(); + await measureRenders(, {scenario}); +}); From c3593a5e52ab6515cdf374e13e4dbb3815c896e5 Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Tue, 1 Sep 2026 15:41:56 +0200 Subject: [PATCH 2/7] perf test update --- ...oneyRequestReportActionsList.perf-test.tsx | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx index dd0fe1a3aa46..23498c3916ad 100644 --- a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx +++ b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx @@ -104,7 +104,7 @@ const report = { lastReadTime: sortedReportActions.at(0)?.created, }; -const transactions = Array.from({length: TRANSACTIONS_COUNT}, (unused, index) => { +function buildTransaction(index: number): Transaction { return { transactionID: `PERF_TXN_${index + 1}`, reportID: REPORT_ID, @@ -114,7 +114,9 @@ const transactions = Array.from({length: TRANSACTIONS_COUNT}, (unused, index) => created: '2025-01-01', status: CONST.TRANSACTION.STATUS.POSTED, } as Transaction; -}); +} + +const transactions = Array.from({length: TRANSACTIONS_COUNT}, (unused, index) => buildTransaction(index)); beforeEach(async () => { // Initialize the network key for OfflineWithFeedback @@ -207,3 +209,34 @@ test('[MoneyRequestReportActionsList] should re-render the unified list when a n await waitForBatchedUpdates(); await measureRenders(, {scenario}); }); + +test('[MoneyRequestReportActionsList] should scope re-renders to the transaction list when a transaction under the report changes', async () => { + const scenario = async () => { + await screen.findByTestId('money-request-report-actions-list'); + // The core claim of the transaction decomposition: mutating one transaction must not + // re-render the report actions portion of the unified list. + await act(async () => { + await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactions.at(0)?.transactionID}`, {amount: 20000, merchant: 'Updated Merchant'}); + await waitForBatchedUpdates(); + }); + }; + await waitForBatchedUpdates(); + await measureRenders(, {scenario}); +}); + +test('[MoneyRequestReportActionsList] should render the unified list with 500 reportActions and 100 transactions stored', async () => { + // Decomposition wins scale with transaction count; this shape makes the delta visible in the baseline diff. + await act(async () => { + for (let index = TRANSACTIONS_COUNT; index < 100; index++) { + const transaction = buildTransaction(index); + // eslint-disable-next-line no-await-in-loop + await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); + } + await waitForBatchedUpdates(); + }); + const scenario = async () => { + await screen.findByTestId('money-request-report-actions-list'); + }; + await waitForBatchedUpdates(); + await measureRenders(, {scenario}); +}); From 03c27b7dea42156dd3ec6110f68ec0b33bb29dc6 Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Tue, 1 Sep 2026 15:57:24 +0200 Subject: [PATCH 3/7] Remove unused eslint-disable directives --- tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx index 23498c3916ad..8657fc8bfe21 100644 --- a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx +++ b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx @@ -186,7 +186,6 @@ test('[MoneyRequestReportActionsList] should not re-render when an unrelated rep // must not re-render because its own report's slice is unchanged. for (let i = 0; i < 5; i++) { const newAction = ReportTestUtils.getFakeReportAction(600 + i, {actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, created: `2023-09-14 00:00:0${i}.000`}); - // eslint-disable-next-line no-await-in-loop await act(async () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${UNRELATED_REPORT_ID}`, {[newAction.reportActionID]: newAction}); await waitForBatchedUpdates(); @@ -229,7 +228,6 @@ test('[MoneyRequestReportActionsList] should render the unified list with 500 re await act(async () => { for (let index = TRANSACTIONS_COUNT; index < 100; index++) { const transaction = buildTransaction(index); - // eslint-disable-next-line no-await-in-loop await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); } await waitForBatchedUpdates(); From 13ad3dbac704001ea73e78be95911efb4b40129c Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Tue, 1 Sep 2026 16:13:34 +0200 Subject: [PATCH 4/7] Make measured Onyx mutations unique per Reassure run --- ...oneyRequestReportActionsList.perf-test.tsx | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx index 8657fc8bfe21..6c92af10a68a 100644 --- a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx +++ b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx @@ -41,6 +41,7 @@ jest.mock('@react-navigation/native', () => { useRoute: () => ({ key: 'test-key', name: SCREENS_MOCK.REPORT, + // Must stay in sync with REPORT_ID above — jest.mock hoisting forbids referencing the constant here. params: {reportID: '1'}, }), useIsFocused: () => true, @@ -178,28 +179,42 @@ test('[MoneyRequestReportActionsList] should render the unified list with 500 re await measureRenders(, {scenario}); }); -test('[MoneyRequestReportActionsList] should not re-render when an unrelated report receives new actions', async () => { +test('[MoneyRequestReportActionsList] should measure re-renders when an unrelated report receives new actions', async () => { const UNRELATED_REPORT_ID = '999'; + // Reassure calls `scenario` once per run (10 runs + warmup) while Onyx is seeded once per test, + // so every run must write actions that don't exist yet — otherwise runs after the first merge + // already-present data and measure a no-op instead of the advertised transition. + let run = 0; const scenario = async () => { await screen.findByTestId('money-request-report-actions-list'); // Each merge recomputes the VISIBLE_REPORT_ACTIONS derived value app-wide; the list under test // must not re-render because its own report's slice is unchanged. for (let i = 0; i < 5; i++) { - const newAction = ReportTestUtils.getFakeReportAction(600 + i, {actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, created: `2023-09-14 00:00:0${i}.000`}); + const newAction = ReportTestUtils.getFakeReportAction(600 + run * 5 + i, { + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + created: `2023-09-14 00:${String(run).padStart(2, '0')}:0${i}.000`, + }); await act(async () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${UNRELATED_REPORT_ID}`, {[newAction.reportActionID]: newAction}); await waitForBatchedUpdates(); }); } + run++; }; await waitForBatchedUpdates(); await measureRenders(, {scenario}); }); test('[MoneyRequestReportActionsList] should re-render the unified list when a new report action arrives', async () => { + // Per-run counter: each Reassure run must add a genuinely new action (see the comment in the test above). + let run = 0; const scenario = async () => { await screen.findByTestId('money-request-report-actions-list'); - const newAction = ReportTestUtils.getFakeReportAction(501, {actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, created: '2023-09-13 00:00:00.000'}); + const newAction = ReportTestUtils.getFakeReportAction(501 + run, { + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + created: `2023-09-13 00:00:${String(run).padStart(2, '0')}.000`, + }); + run++; await act(async () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[newAction.reportActionID]: newAction}); await waitForBatchedUpdates(); @@ -209,13 +224,16 @@ test('[MoneyRequestReportActionsList] should re-render the unified list when a n await measureRenders(, {scenario}); }); -test('[MoneyRequestReportActionsList] should scope re-renders to the transaction list when a transaction under the report changes', async () => { +test('[MoneyRequestReportActionsList] should measure re-renders when a transaction under the report changes', async () => { + // Per-run counter: each Reassure run must write a value that differs from the stored one (see above). + let run = 0; const scenario = async () => { await screen.findByTestId('money-request-report-actions-list'); // The core claim of the transaction decomposition: mutating one transaction must not // re-render the report actions portion of the unified list. + run++; await act(async () => { - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactions.at(0)?.transactionID}`, {amount: 20000, merchant: 'Updated Merchant'}); + await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactions.at(0)?.transactionID}`, {amount: 20000 + run * 100, merchant: `Updated Merchant ${run}`}); await waitForBatchedUpdates(); }); }; @@ -225,11 +243,18 @@ test('[MoneyRequestReportActionsList] should scope re-renders to the transaction test('[MoneyRequestReportActionsList] should render the unified list with 500 reportActions and 100 transactions stored', async () => { // Decomposition wins scale with transaction count; this shape makes the delta visible in the baseline diff. + const LARGE_TRANSACTIONS_COUNT = 100; await act(async () => { - for (let index = TRANSACTIONS_COUNT; index < 100; index++) { - const transaction = buildTransaction(index); - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); - } + const extraTransactions = Object.fromEntries( + Array.from({length: LARGE_TRANSACTIONS_COUNT - TRANSACTIONS_COUNT}, (unused, index) => { + const transaction = buildTransaction(TRANSACTIONS_COUNT + index); + return [`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction]; + }), + ); + // One multiSet write: 90 sequential sets would each trigger a full REPORT_TRANSACTIONS_AND_VIOLATIONS recompute. + await Onyx.multiSet(extraTransactions); + // Keep the report total consistent with the enlarged transaction set. + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, {total: 10000 * LARGE_TRANSACTIONS_COUNT}); await waitForBatchedUpdates(); }); const scenario = async () => { From 1c149ea2df2981d12f8147e674853009b8e9fbed Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Tue, 1 Sep 2026 16:16:50 +0200 Subject: [PATCH 5/7] Remove comments --- ...oneyRequestReportActionsList.perf-test.tsx | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx index 6c92af10a68a..8550aec877f4 100644 --- a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx +++ b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx @@ -59,13 +59,10 @@ beforeAll(() => { keys: ONYXKEYS, evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], }); - // Register the derived-value computations (e.g. VISIBLE_REPORT_ACTIONS): without this the derived - // keys never update in the test, hiding production re-render behavior from the measurements. initOnyxDerivedValues(); }); const mockOnLayout = jest.fn(); -// Built via a function so the value isn't an inline literal the context-split lint rule would flag; these are all refs/accessors with no re-render concern. function buildActionListContextValue() { return {scrollOffsetRef: {current: 0}, getScrollOffset: () => 0, registerListRef: () => {}, getListRef: () => null}; } @@ -75,8 +72,6 @@ const mockReactionListContextValue = { hideReactionList: () => {}, isActiveReportAction: () => false, }; -// Transaction items resolve their highlight animation via ScreenWrapper's transition status; the -// perf harness renders no ScreenWrapper, so provide a settled one. const screenWrapperStatusContextValue = { didScreenTransitionEnd: true, isSafeAreaTopPaddingApplied: false, @@ -100,8 +95,6 @@ const report = { policyID: POLICY_ID, total: 10000 * TRANSACTIONS_COUNT, currency: CONST.CURRENCY.USD, - // Seed the report as already read so mount doesn't fire readNewestAction (a network action whose - // timing would add noise to the measurement). lastReadTime: sortedReportActions.at(0)?.created, }; @@ -120,16 +113,12 @@ function buildTransaction(index: number): Transaction { const transactions = Array.from({length: TRANSACTIONS_COUNT}, (unused, index) => buildTransaction(index)); beforeEach(async () => { - // Initialize the network key for OfflineWithFeedback setHasRadio(true); wrapOnyxWithWaitForBatchedUpdates(Onyx); - // Pre-seed the locale so LocaleContextProvider's mount effect is a no-op (setLocale early-returns), - // avoiding post-mount Onyx writes that would re-render outside act(). await act(async () => { signUpWithTestUser(); await Onyx.merge(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.DEFAULT); - // Seed the report under test: the expense report, its 500 actions, its transactions, and a settled loading state. await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, reportActions); for (const transaction of transactions) { @@ -148,7 +137,6 @@ beforeEach(async () => { }); afterEach(async () => { - // Await the clear so its broadcasts settle in teardown instead of leaking into the next test. await Onyx.clear(); await waitForBatchedUpdates(); }); @@ -187,8 +175,6 @@ test('[MoneyRequestReportActionsList] should measure re-renders when an unrelate let run = 0; const scenario = async () => { await screen.findByTestId('money-request-report-actions-list'); - // Each merge recomputes the VISIBLE_REPORT_ACTIONS derived value app-wide; the list under test - // must not re-render because its own report's slice is unchanged. for (let i = 0; i < 5; i++) { const newAction = ReportTestUtils.getFakeReportAction(600 + run * 5 + i, { actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, @@ -206,7 +192,6 @@ test('[MoneyRequestReportActionsList] should measure re-renders when an unrelate }); test('[MoneyRequestReportActionsList] should re-render the unified list when a new report action arrives', async () => { - // Per-run counter: each Reassure run must add a genuinely new action (see the comment in the test above). let run = 0; const scenario = async () => { await screen.findByTestId('money-request-report-actions-list'); @@ -225,12 +210,9 @@ test('[MoneyRequestReportActionsList] should re-render the unified list when a n }); test('[MoneyRequestReportActionsList] should measure re-renders when a transaction under the report changes', async () => { - // Per-run counter: each Reassure run must write a value that differs from the stored one (see above). let run = 0; const scenario = async () => { await screen.findByTestId('money-request-report-actions-list'); - // The core claim of the transaction decomposition: mutating one transaction must not - // re-render the report actions portion of the unified list. run++; await act(async () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactions.at(0)?.transactionID}`, {amount: 20000 + run * 100, merchant: `Updated Merchant ${run}`}); @@ -242,7 +224,6 @@ test('[MoneyRequestReportActionsList] should measure re-renders when a transacti }); test('[MoneyRequestReportActionsList] should render the unified list with 500 reportActions and 100 transactions stored', async () => { - // Decomposition wins scale with transaction count; this shape makes the delta visible in the baseline diff. const LARGE_TRANSACTIONS_COUNT = 100; await act(async () => { const extraTransactions = Object.fromEntries( @@ -251,9 +232,7 @@ test('[MoneyRequestReportActionsList] should render the unified list with 500 re return [`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction]; }), ); - // One multiSet write: 90 sequential sets would each trigger a full REPORT_TRANSACTIONS_AND_VIOLATIONS recompute. await Onyx.multiSet(extraTransactions); - // Keep the report total consistent with the enlarged transaction set. await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, {total: 10000 * LARGE_TRANSACTIONS_COUNT}); await waitForBatchedUpdates(); }); From e7c562723a107a4b90bebe52356138a2ffdd2a76 Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Tue, 1 Sep 2026 16:20:02 +0200 Subject: [PATCH 6/7] Fix multiSet input typing --- .../MoneyRequestReportActionsList.perf-test.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx index 8550aec877f4..00e0c5bf09e4 100644 --- a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx +++ b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx @@ -22,6 +22,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import type {ReportAction, ReportActions, Transaction} from '@src/types/onyx'; +import type {OnyxMultiSetInput} from 'react-native-onyx'; + import {NavigationContainer} from '@react-navigation/native'; import Onyx from 'react-native-onyx'; import {measureRenders} from 'reassure'; @@ -226,12 +228,11 @@ test('[MoneyRequestReportActionsList] should measure re-renders when a transacti test('[MoneyRequestReportActionsList] should render the unified list with 500 reportActions and 100 transactions stored', async () => { const LARGE_TRANSACTIONS_COUNT = 100; await act(async () => { - const extraTransactions = Object.fromEntries( - Array.from({length: LARGE_TRANSACTIONS_COUNT - TRANSACTIONS_COUNT}, (unused, index) => { - const transaction = buildTransaction(TRANSACTIONS_COUNT + index); - return [`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction]; - }), - ); + const extraTransactions: OnyxMultiSetInput = {}; + for (let index = TRANSACTIONS_COUNT; index < LARGE_TRANSACTIONS_COUNT; index++) { + const transaction = buildTransaction(index); + extraTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`] = transaction; + } await Onyx.multiSet(extraTransactions); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, {total: 10000 * LARGE_TRANSACTIONS_COUNT}); await waitForBatchedUpdates(); From 766a30067c450fc00521540c4bc39e6762dbdc51 Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Wed, 2 Sep 2026 09:10:46 +0200 Subject: [PATCH 7/7] Modify tests to follow Given / When / Then structrue" --- ...oneyRequestReportActionsList.perf-test.tsx | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx index 00e0c5bf09e4..2612279780e1 100644 --- a/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx +++ b/tests/perf-test/MoneyRequestReportActionsList.perf-test.tsx @@ -163,9 +163,14 @@ function MoneyRequestReportActionsListWrapper() { test('[MoneyRequestReportActionsList] should render the unified list with 500 reportActions and 10 transactions stored', async () => { const scenario = async () => { + // Then the unified list should be rendered await screen.findByTestId('money-request-report-actions-list'); }; + + // Given an expense report with 500 report actions and 10 transactions seeded in Onyx await waitForBatchedUpdates(); + + // When the list is mounted await measureRenders(, {scenario}); }); @@ -176,7 +181,10 @@ test('[MoneyRequestReportActionsList] should measure re-renders when an unrelate // already-present data and measure a no-op instead of the advertised transition. let run = 0; const scenario = async () => { + // Given the unified list is rendered for the seeded report await screen.findByTestId('money-request-report-actions-list'); + + // When 5 new report actions arrive on a different, unrelated report for (let i = 0; i < 5; i++) { const newAction = ReportTestUtils.getFakeReportAction(600 + run * 5 + i, { actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, @@ -190,13 +198,18 @@ test('[MoneyRequestReportActionsList] should measure re-renders when an unrelate run++; }; await waitForBatchedUpdates(); + + // Then reassure should measure the re-renders caused by the unrelated updates (ideally none) await measureRenders(, {scenario}); }); test('[MoneyRequestReportActionsList] should re-render the unified list when a new report action arrives', async () => { let run = 0; const scenario = async () => { + // Given the unified list is rendered for the seeded report await screen.findByTestId('money-request-report-actions-list'); + + // When a new report action arrives on this report const newAction = ReportTestUtils.getFakeReportAction(501 + run, { actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, created: `2023-09-13 00:00:${String(run).padStart(2, '0')}.000`, @@ -208,25 +221,34 @@ test('[MoneyRequestReportActionsList] should re-render the unified list when a n }); }; await waitForBatchedUpdates(); + + // Then reassure should measure the re-renders caused by the new action await measureRenders(, {scenario}); }); test('[MoneyRequestReportActionsList] should measure re-renders when a transaction under the report changes', async () => { let run = 0; const scenario = async () => { + // Given the unified list is rendered for the seeded report await screen.findByTestId('money-request-report-actions-list'); run++; + + // When a transaction that belongs to the report changes its amount and merchant await act(async () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactions.at(0)?.transactionID}`, {amount: 20000 + run * 100, merchant: `Updated Merchant ${run}`}); await waitForBatchedUpdates(); }); }; await waitForBatchedUpdates(); + + // Then reassure should measure the re-renders caused by the transaction update await measureRenders(, {scenario}); }); test('[MoneyRequestReportActionsList] should render the unified list with 500 reportActions and 100 transactions stored', async () => { const LARGE_TRANSACTIONS_COUNT = 100; + + // Given the report is topped up to 100 transactions in Onyx await act(async () => { const extraTransactions: OnyxMultiSetInput = {}; for (let index = TRANSACTIONS_COUNT; index < LARGE_TRANSACTIONS_COUNT; index++) { @@ -238,8 +260,11 @@ test('[MoneyRequestReportActionsList] should render the unified list with 500 re await waitForBatchedUpdates(); }); const scenario = async () => { + // Then the unified list should be rendered await screen.findByTestId('money-request-report-actions-list'); }; await waitForBatchedUpdates(); + + // When the list is mounted await measureRenders(, {scenario}); });