-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Precompute sorted report IDs in Search to avoid duplicated sorting #86238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Julesssss
merged 21 commits into
Expensify:main
from
callstack-internal:perf/search-sections-precompute
May 19, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
45df747
Precompute sorted report IDs in Search to avoid duplicate getSections…
leshniak 9d2936c
Rename useSortedSearchResults/useSearchNavigationState to useSearchSe…
leshniak b90bfcd
Simplify useSearchSections interface and fix sortedReportIDs paginati…
leshniak 5b1cb48
Move sorted report IDs from Onyx to Search context
leshniak da38d8a
Move setSortedReportIDs effect into useSearchSections
leshniak 7ef0211
Extract sortedReportIDs as useMemo for React Compiler compliance
leshniak a8013a5
perf: add render instrumentation to MoneyRequestReportNavigation
leshniak 84a2a61
perf: improve render instrumentation with timing and item count
leshniak e88c2b4
Merge upstream/main — adopt shouldShowActionsBarLoading rename and us…
leshniak 2b1a49b
Extract useFilterPendingDeleteReports hook
leshniak f1bc6a6
Add sortedReportIDs state to SearchContext
leshniak 877b5e9
Precompute sorted report IDs in Search via useSaveSortedReportIDs
leshniak b00fda0
Fast-path MoneyRequestReportNavigation via pre-computed context IDs
leshniak c9c40e4
Add tests for MoneyRequestReportNavigation routing and useSearchSections
leshniak 78706ca
Fix tsc error: cast partial Report mock to unknown first
leshniak 98a7645
perf-11 fixes
leshniak 8d9171a
linter fix
leshniak 4ce6f7f
Merge remote-tracking branch 'upstream/main' into perf/search-section…
leshniak a90e96e
Merge remote-tracking branch 'upstream/main' into perf/search-section…
leshniak 2120637
Merge remote-tracking branch 'upstream/main' into perf/search-section…
leshniak 9a25389
Remove unused eslint-disable directives for @typescript-eslint/naming…
leshniak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
| import {isReportPendingDelete} from '@libs/ReportUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Report} from '@src/types/onyx'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Returns sorted keys of reports pending deletion. | ||
| * Sorted string[] keeps Onyx comparison cheap (PERF-11). | ||
| */ | ||
| const selectPendingDeleteReportKeys = (reports: OnyxCollection<Report>): string[] => { | ||
| const keys: string[] = []; | ||
| for (const [key, report] of Object.entries(reports ?? {})) { | ||
| if (isReportPendingDelete(report)) { | ||
| keys.push(key); | ||
| } | ||
| } | ||
| return keys.sort(); | ||
| }; | ||
|
|
||
| /** | ||
| * Filters out report IDs whose corresponding reports have a pending DELETE action. | ||
| * Subscribes to the REPORT collection with a lightweight selector to minimize re-renders. | ||
| */ | ||
| function useFilterPendingDeleteReports(ids: ReadonlyArray<string | undefined>): Array<string | undefined> { | ||
| const [pendingDeleteReportKeys = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: selectPendingDeleteReportKeys}); | ||
| const pendingDeleteReportKeysSet = new Set(pendingDeleteReportKeys); | ||
|
|
||
| return ids.filter((id) => { | ||
| if (!id) { | ||
| return false; | ||
| } | ||
| return !pendingDeleteReportKeysSet.has(`${ONYXKEYS.COLLECTION.REPORT}${id}`); | ||
| }); | ||
| } | ||
|
|
||
| export {selectPendingDeleteReportKeys}; | ||
| export default useFilterPendingDeleteReports; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import {useEffect} from 'react'; | ||
| import {useSearchActionsContext} from '@components/Search/SearchContext'; | ||
| import CONST from '@src/CONST'; | ||
| import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; | ||
|
|
||
| /** | ||
| * Persists sorted report IDs to Search context so that MoneyRequestReportNavigation | ||
| * can read them without recomputing getSortedSections. | ||
| * Only stores IDs for expense-report searches; clears the context for all other types | ||
| * to force the fallback computation in the navigation header. | ||
| */ | ||
| function useSaveSortedReportIDs(type: SearchDataTypes, items: Array<{reportID?: string | undefined}>) { | ||
| const {setSortedReportIDs} = useSearchActionsContext(); | ||
|
|
||
| useEffect(() => { | ||
| // Only expense-report searches produce report-level IDs suitable for navigation arrows. | ||
| // For all other types (expense, invoice, etc.) the items are transaction-level and share | ||
| // reportIDs, so we clear the context to force the fallback computation in navigation. | ||
| if (type !== CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) { | ||
| setSortedReportIDs([]); | ||
| return; | ||
| } | ||
|
|
||
| const reportIDs = items.map((item) => item.reportID); | ||
|
|
||
| setSortedReportIDs(reportIDs); | ||
| }, [type, items, setSortedReportIDs]); | ||
| } | ||
|
|
||
| export default useSaveSortedReportIDs; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching back to the fast path as soon as
isSearchLoadingbecomes false can reuse a stalesortedReportIDslist aftersearch()loads another page from the report view. In that window (or whenever Search isn’t mounted to refresh context),allReportsmay still contain only the old page, so pressing Next at the end of loaded results wraps to the first item instead of navigating into newly fetched reports. The fallback should remain active until the context IDs are confirmed to match the updated snapshot/query state.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works only with
expense-reportsin Search, so if the user actively browses expense reports. It falls back to the full logic in every other case.