Skip to content

Commit 909ed63

Browse files
authored
Clean up context access profiling experiment (#31806)
We introduced the `unstable_useContextWithBailout` API to run compiler based experiments. This API was designed to be an experiment proxy for alternative approaches which would be heavier to implement. The experiment turned out to be inconclusive. Since most of our performance critical usage is already optimized, we weren't able to find a clear win with this approach. Since we don't have further plans for this API, let's clean it up.
1 parent 031230d commit 909ed63

15 files changed

+16
-548
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type {
2020
Dependencies,
2121
Fiber,
2222
Dispatcher as DispatcherType,
23-
ContextDependencyWithSelect,
2423
} from 'react-reconciler/src/ReactInternalTypes';
2524
import type {TransitionStatus} from 'react-reconciler/src/ReactFiberConfig';
2625

@@ -76,13 +75,6 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
7675
try {
7776
// Use all hooks here to add them to the hook log.
7877
Dispatcher.useContext(({_currentValue: null}: any));
79-
if (typeof Dispatcher.unstable_useContextWithBailout === 'function') {
80-
// This type check is for Flow only.
81-
Dispatcher.unstable_useContextWithBailout(
82-
({_currentValue: null}: any),
83-
null,
84-
);
85-
}
8678
Dispatcher.useState(null);
8779
Dispatcher.useReducer((s: mixed, a: mixed) => s, null);
8880
Dispatcher.useRef(null);
@@ -150,10 +142,7 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
150142

151143
let currentFiber: null | Fiber = null;
152144
let currentHook: null | Hook = null;
153-
let currentContextDependency:
154-
| null
155-
| ContextDependency<mixed>
156-
| ContextDependencyWithSelect<mixed> = null;
145+
let currentContextDependency: null | ContextDependency<mixed> = null;
157146

158147
function nextHook(): null | Hook {
159148
const hook = currentHook;
@@ -274,22 +263,6 @@ function useContext<T>(context: ReactContext<T>): T {
274263
return value;
275264
}
276265

277-
function unstable_useContextWithBailout<T>(
278-
context: ReactContext<T>,
279-
select: (T => Array<mixed>) | null,
280-
): T {
281-
const value = readContext(context);
282-
hookLog.push({
283-
displayName: context.displayName || null,
284-
primitive: 'ContextWithBailout',
285-
stackError: new Error(),
286-
value: value,
287-
debugInfo: null,
288-
dispatcherHookName: 'ContextWithBailout',
289-
});
290-
return value;
291-
}
292-
293266
function useState<S>(
294267
initialState: (() => S) | S,
295268
): [S, Dispatch<BasicStateAction<S>>] {
@@ -764,7 +737,6 @@ const Dispatcher: DispatcherType = {
764737
useCacheRefresh,
765738
useCallback,
766739
useContext,
767-
unstable_useContextWithBailout,
768740
useEffect,
769741
useImperativeHandle,
770742
useDebugValue,

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ import {
3939
enableLazyContextPropagation,
4040
enableTransitionTracing,
4141
enableUseEffectEventHook,
42+
enableUseResourceEffectHook,
4243
enableLegacyCache,
4344
debugRenderPhaseSideEffectsForStrictMode,
4445
disableLegacyMode,
4546
enableNoCloningMemoCache,
46-
enableContextProfiling,
47-
enableUseResourceEffectHook,
4847
} from 'shared/ReactFeatureFlags';
4948
import {
5049
REACT_CONTEXT_TYPE,
@@ -78,11 +77,7 @@ import {
7877
ContinuousEventPriority,
7978
higherEventPriority,
8079
} from './ReactEventPriorities';
81-
import {
82-
readContext,
83-
readContextAndCompare,
84-
checkIfContextChanged,
85-
} from './ReactFiberNewContext';
80+
import {readContext, checkIfContextChanged} from './ReactFiberNewContext';
8681
import {HostRoot, CacheComponent, HostComponent} from './ReactWorkTags';
8782
import {
8883
LayoutStatic as LayoutStaticEffect,
@@ -1111,16 +1106,6 @@ function updateWorkInProgressHook(): Hook {
11111106
return workInProgressHook;
11121107
}
11131108

1114-
function unstable_useContextWithBailout<T>(
1115-
context: ReactContext<T>,
1116-
select: (T => Array<mixed>) | null,
1117-
): T {
1118-
if (select === null) {
1119-
return readContext(context);
1120-
}
1121-
return readContextAndCompare(context, select);
1122-
}
1123-
11241109
function createFunctionComponentUpdateQueue(): FunctionComponentUpdateQueue {
11251110
return {
11261111
lastEffect: null,
@@ -3958,10 +3943,6 @@ if (enableUseEffectEventHook) {
39583943
if (enableUseResourceEffectHook) {
39593944
(ContextOnlyDispatcher: Dispatcher).useResourceEffect = throwInvalidHookError;
39603945
}
3961-
if (enableContextProfiling) {
3962-
(ContextOnlyDispatcher: Dispatcher).unstable_useContextWithBailout =
3963-
throwInvalidHookError;
3964-
}
39653946

39663947
const HooksDispatcherOnMount: Dispatcher = {
39673948
readContext,
@@ -3995,10 +3976,6 @@ if (enableUseEffectEventHook) {
39953976
if (enableUseResourceEffectHook) {
39963977
(HooksDispatcherOnMount: Dispatcher).useResourceEffect = mountResourceEffect;
39973978
}
3998-
if (enableContextProfiling) {
3999-
(HooksDispatcherOnMount: Dispatcher).unstable_useContextWithBailout =
4000-
unstable_useContextWithBailout;
4001-
}
40023979

40033980
const HooksDispatcherOnUpdate: Dispatcher = {
40043981
readContext,
@@ -4033,10 +4010,6 @@ if (enableUseResourceEffectHook) {
40334010
(HooksDispatcherOnUpdate: Dispatcher).useResourceEffect =
40344011
updateResourceEffect;
40354012
}
4036-
if (enableContextProfiling) {
4037-
(HooksDispatcherOnUpdate: Dispatcher).unstable_useContextWithBailout =
4038-
unstable_useContextWithBailout;
4039-
}
40404013

40414014
const HooksDispatcherOnRerender: Dispatcher = {
40424015
readContext,
@@ -4071,10 +4044,6 @@ if (enableUseResourceEffectHook) {
40714044
(HooksDispatcherOnRerender: Dispatcher).useResourceEffect =
40724045
updateResourceEffect;
40734046
}
4074-
if (enableContextProfiling) {
4075-
(HooksDispatcherOnRerender: Dispatcher).unstable_useContextWithBailout =
4076-
unstable_useContextWithBailout;
4077-
}
40784047

40794048
let HooksDispatcherOnMountInDEV: Dispatcher | null = null;
40804049
let HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher | null = null;
@@ -4296,17 +4265,6 @@ if (__DEV__) {
42964265
);
42974266
};
42984267
}
4299-
if (enableContextProfiling) {
4300-
(HooksDispatcherOnMountInDEV: Dispatcher).unstable_useContextWithBailout =
4301-
function <T>(
4302-
context: ReactContext<T>,
4303-
select: (T => Array<mixed>) | null,
4304-
): T {
4305-
currentHookNameInDev = 'useContext';
4306-
mountHookTypesDev();
4307-
return unstable_useContextWithBailout(context, select);
4308-
};
4309-
}
43104268

43114269
HooksDispatcherOnMountWithHookTypesInDEV = {
43124270
readContext<T>(context: ReactContext<T>): T {
@@ -4494,17 +4452,6 @@ if (__DEV__) {
44944452
);
44954453
};
44964454
}
4497-
if (enableContextProfiling) {
4498-
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).unstable_useContextWithBailout =
4499-
function <T>(
4500-
context: ReactContext<T>,
4501-
select: (T => Array<mixed>) | null,
4502-
): T {
4503-
currentHookNameInDev = 'useContext';
4504-
updateHookTypesDev();
4505-
return unstable_useContextWithBailout(context, select);
4506-
};
4507-
}
45084455

45094456
HooksDispatcherOnUpdateInDEV = {
45104457
readContext<T>(context: ReactContext<T>): T {
@@ -4692,17 +4639,6 @@ if (__DEV__) {
46924639
);
46934640
};
46944641
}
4695-
if (enableContextProfiling) {
4696-
(HooksDispatcherOnUpdateInDEV: Dispatcher).unstable_useContextWithBailout =
4697-
function <T>(
4698-
context: ReactContext<T>,
4699-
select: (T => Array<mixed>) | null,
4700-
): T {
4701-
currentHookNameInDev = 'useContext';
4702-
updateHookTypesDev();
4703-
return unstable_useContextWithBailout(context, select);
4704-
};
4705-
}
47064642

47074643
HooksDispatcherOnRerenderInDEV = {
47084644
readContext<T>(context: ReactContext<T>): T {
@@ -4890,17 +4826,6 @@ if (__DEV__) {
48904826
);
48914827
};
48924828
}
4893-
if (enableContextProfiling) {
4894-
(HooksDispatcherOnRerenderInDEV: Dispatcher).unstable_useContextWithBailout =
4895-
function <T>(
4896-
context: ReactContext<T>,
4897-
select: (T => Array<mixed>) | null,
4898-
): T {
4899-
currentHookNameInDev = 'useContext';
4900-
updateHookTypesDev();
4901-
return unstable_useContextWithBailout(context, select);
4902-
};
4903-
}
49044829

49054830
InvalidNestedHooksDispatcherOnMountInDEV = {
49064831
readContext<T>(context: ReactContext<T>): T {
@@ -5114,18 +5039,6 @@ if (__DEV__) {
51145039
);
51155040
};
51165041
}
5117-
if (enableContextProfiling) {
5118-
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).unstable_useContextWithBailout =
5119-
function <T>(
5120-
context: ReactContext<T>,
5121-
select: (T => Array<mixed>) | null,
5122-
): T {
5123-
currentHookNameInDev = 'useContext';
5124-
warnInvalidHookAccess();
5125-
mountHookTypesDev();
5126-
return unstable_useContextWithBailout(context, select);
5127-
};
5128-
}
51295042

51305043
InvalidNestedHooksDispatcherOnUpdateInDEV = {
51315044
readContext<T>(context: ReactContext<T>): T {
@@ -5339,18 +5252,6 @@ if (__DEV__) {
53395252
);
53405253
};
53415254
}
5342-
if (enableContextProfiling) {
5343-
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).unstable_useContextWithBailout =
5344-
function <T>(
5345-
context: ReactContext<T>,
5346-
select: (T => Array<mixed>) | null,
5347-
): T {
5348-
currentHookNameInDev = 'useContext';
5349-
warnInvalidHookAccess();
5350-
updateHookTypesDev();
5351-
return unstable_useContextWithBailout(context, select);
5352-
};
5353-
}
53545255

53555256
InvalidNestedHooksDispatcherOnRerenderInDEV = {
53565257
readContext<T>(context: ReactContext<T>): T {
@@ -5564,16 +5465,4 @@ if (__DEV__) {
55645465
);
55655466
};
55665467
}
5567-
if (enableContextProfiling) {
5568-
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).unstable_useContextWithBailout =
5569-
function <T>(
5570-
context: ReactContext<T>,
5571-
select: (T => Array<mixed>) | null,
5572-
): T {
5573-
currentHookNameInDev = 'useContext';
5574-
warnInvalidHookAccess();
5575-
updateHookTypesDev();
5576-
return unstable_useContextWithBailout(context, select);
5577-
};
5578-
}
55795468
}

0 commit comments

Comments
 (0)