Repository navigation
[No QA] perf: replace PersonalDetails selectors with hooks to avoid expensive deepEqual #82646
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
mountiny
merged 16 commits into
Expensify:main
from
callstack-internal:perf/personal-details-selectors
Feb 24, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b8428a0
perf: replace PersonalDetails selectors with hooks to avoid expensive…
TMisiukiewicz dde9575
update useMappedPersonalDetails
TMisiukiewicz 5ebabbf
Add sentryLabel to ApprovalWorkflowSection pressable
TMisiukiewicz f75764e
Merge remote-tracking branch 'origin/main' into perf/personal-details…
TMisiukiewicz ab6e46f
fix prettier
TMisiukiewicz 54e36ce
Consolidate personalDetailMapper into useMappedPersonalDetails
TMisiukiewicz 2755097
Merge remote-tracking branch 'origin/main' into perf/personal-details…
TMisiukiewicz a8b8061
fix lint warnings and add unit tests for personal details hooks
TMisiukiewicz b3a4596
Merge remote-tracking branch 'origin/main' into perf/personal-details…
TMisiukiewicz 27aee5d
add unit tests for ReportWelcomeText to fix coverage drop
TMisiukiewicz 244b4e5
fix TS errors: default import for personalDetailsSelector and fix pol…
TMisiukiewicz af0035c
Merge remote-tracking branch 'origin/main' into perf/personal-details…
TMisiukiewicz d29c6d3
Consolidate duplicate hook test files into tests/unit/hooks/
TMisiukiewicz 3a1a615
Merge origin/main into perf/personal-details-selectors
TMisiukiewicz 21c35eb
fix ts
TMisiukiewicz 4ce68a9
Merge remote-tracking branch 'origin/main' into perf/personal-details…
TMisiukiewicz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {OnyxInputOrEntry, PersonalDetails} from '@src/types/onyx'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| const personalDetailMapper = (personalDetail: OnyxInputOrEntry<PersonalDetails>): OnyxInputOrEntry<PersonalDetails> => | ||
| personalDetail && { | ||
| accountID: personalDetail.accountID, | ||
| login: personalDetail.login, | ||
| avatar: personalDetail.avatar, | ||
| pronouns: personalDetail.pronouns, | ||
| }; | ||
|
|
||
| /** | ||
| * Subscribes to all personal details and transforms each one via the provided mapper. | ||
| * Unlike passing a selector directly to useOnyx (which triggers expensive deepEqual | ||
| * comparisons on the entire mapped collection), this hook lets Onyx use cheap | ||
| * shallowEqual on raw personal detail references, then maps the collection inline. | ||
| */ | ||
| function useMappedPersonalDetails<T>(mapper: (personalDetail: OnyxEntry<PersonalDetails>) => T) { | ||
| const [personalDetails, metadata] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); | ||
| const transformed = Object.entries(personalDetails ?? {}).reduce<Record<string, T>>((acc, [key, entry]) => { | ||
| acc[key] = mapper(entry ?? undefined); | ||
| return acc; | ||
| }, {}); | ||
|
TMisiukiewicz marked this conversation as resolved.
Resolved
|
||
|
|
||
| return [transformed, metadata] as const; | ||
| } | ||
|
|
||
| export {personalDetailMapper}; | ||
| export default useMappedPersonalDetails; | ||
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,18 @@ | ||
| import lodashMapKeys from 'lodash/mapKeys'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Subscribes to all personal details and remaps them by email (login) instead of account ID. | ||
| * Unlike passing a selector directly to useOnyx (which triggers expensive deepEqual | ||
| * comparisons on the entire mapped collection), this hook lets Onyx use cheap | ||
| * shallowEqual on raw personal detail references, then remaps inline. | ||
| */ | ||
| function usePersonalDetailsByEmail() { | ||
| const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); | ||
| const result = personalDetails ? lodashMapKeys(personalDetails, (value, key) => value?.login ?? key) : undefined; | ||
|
TMisiukiewicz marked this conversation as resolved.
Resolved
|
||
|
|
||
| return result; | ||
| } | ||
|
|
||
| export default usePersonalDetailsByEmail; | ||
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
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 |
|---|---|---|
| @@ -1,16 +1,6 @@ | ||
| import lodashMapKeys from 'lodash/mapKeys'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import type {OnyxInputOrEntry, PersonalDetails, PersonalDetailsList} from '@src/types/onyx'; | ||
| import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; | ||
|
|
||
| type PersonalDetailsSelector<T> = (personalDetails: OnyxInputOrEntry<PersonalDetails>) => T; | ||
|
|
||
| const createPersonalDetailsSelector = <T>(personalDetails: OnyxEntry<PersonalDetailsList>, personalDetailsSelector: PersonalDetailsSelector<T>) => | ||
| mapOnyxCollectionItems(personalDetails, personalDetailsSelector); | ||
|
|
||
| const personalDetailsByEmailSelector = (personalDetails: OnyxEntry<PersonalDetailsList>) => | ||
| personalDetails ? lodashMapKeys(personalDetails, (value, key) => value?.login ?? key) : undefined; | ||
| import type {PersonalDetailsList} from '@src/types/onyx'; | ||
|
|
||
| const personalDetailsSelector = (accountID: number) => (personalDetailsList: OnyxEntry<PersonalDetailsList>) => personalDetailsList?.[accountID]; | ||
|
|
||
| export {createPersonalDetailsSelector, personalDetailsByEmailSelector, personalDetailsSelector}; | ||
| export default personalDetailsSelector; |
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.
Uh oh!
There was an error while loading. Please reload this page.