Skip to content

Commit

Permalink
More memoization in useFragmentInternal
Browse files Browse the repository at this point in the history
Summary:
Adds some extra memoization in useFragmentInternal() to reduce work in the common case. Specifically, by memoizing the selector we ensure that the `areEqualSelectors()` call can hit the fast path, quickly bailing out when the inputs are `===`.

This also avoids unnecessarily running effects related to missing client edges (a further optimization would be to use static knowledge of the fragment to avoid running effects *at all* if we know the fragment can never have client edges).

Reviewed By: voideanvalue

Differential Revision: D36649352

fbshipit-source-id: 8ae7801a3d2644b2de162985dc650739731e18aa
  • Loading branch information
josephsavona authored and facebook-github-bot committed May 26, 2022
1 parent af5f6c5 commit 73f01ac
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ function useFragmentInternal_REACT_CACHE(
queryOptions?: FragmentQueryOptions,
fragmentKey?: string,
): ?SelectorData | Array<?SelectorData> {
const fragmentSelector = getSelector(fragmentNode, fragmentRef);
const fragmentSelector = useMemo(
() => getSelector(fragmentNode, fragmentRef),
[fragmentNode, fragmentRef],
);

const isPlural = fragmentNode?.metadata?.plural === true;

Expand Down

0 comments on commit 73f01ac

Please sign in to comment.