From 4d686a2da138cad9e76c7de9feadd81ca2aa29e5 Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Mon, 18 Mar 2024 11:54:34 -0400 Subject: [PATCH] Performance: avoid triggering map deopt in V8 (#28569) The shape of the objects changed by this PR are both created in 2 locations with 2 different shapes, which most JS engines won't like. I've noticed this in particular in V8 while benchmarking production code. https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberCacheComponent.js#L66-L77 https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberHostContext.js#L47-L54 https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberHooks.js#L3530-L3531 https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberHooks.js#L3492-L3493 --- packages/react-reconciler/src/ReactFiberHooks.js | 2 +- packages/react-reconciler/src/ReactFiberHostContext.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index 75acffc1b9a11..ecb707608ebc4 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -3489,8 +3489,8 @@ export const ContextOnlyDispatcher: Dispatcher = { useContext: throwInvalidHookError, useEffect: throwInvalidHookError, useImperativeHandle: throwInvalidHookError, - useInsertionEffect: throwInvalidHookError, useLayoutEffect: throwInvalidHookError, + useInsertionEffect: throwInvalidHookError, useMemo: throwInvalidHookError, useReducer: throwInvalidHookError, useRef: throwInvalidHookError, diff --git a/packages/react-reconciler/src/ReactFiberHostContext.js b/packages/react-reconciler/src/ReactFiberHostContext.js index 3ba99edb239ad..0b64be766a95b 100644 --- a/packages/react-reconciler/src/ReactFiberHostContext.js +++ b/packages/react-reconciler/src/ReactFiberHostContext.js @@ -46,11 +46,11 @@ const hostTransitionProviderCursor: StackCursor = // inside useHostTransitionStatus. export const HostTransitionContext: ReactContext = { $$typeof: REACT_CONTEXT_TYPE, + Provider: (null: any), + Consumer: (null: any), _currentValue: null, _currentValue2: null, _threadCount: 0, - Provider: (null: any), - Consumer: (null: any), }; function requiredContext(c: Value | null): Value {