Skip to content

Commit

Permalink
Clean up context access profiling experiment (#31806)
Browse files Browse the repository at this point in the history
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.

DiffTrain build for [909ed63](909ed63)
  • Loading branch information
jackpope committed Dec 16, 2024
1 parent 517de85 commit cd62d05
Show file tree
Hide file tree
Showing 34 changed files with 874 additions and 2,402 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f7b1273da2c96057d3908f52f8587379d4418f66
909ed63e0adc162a95a4704d3ed07a956dcf9cd1
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f7b1273da2c96057d3908f52f8587379d4418f66
909ed63e0adc162a95a4704d3ed07a956dcf9cd1
10 changes: 1 addition & 9 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1870,14 +1870,6 @@ __DEV__ &&
exports.unstable_useCacheRefresh = function () {
return resolveDispatcher().useCacheRefresh();
};
exports.unstable_useContextWithBailout = function (context, select) {
var dispatcher = resolveDispatcher();
context.$$typeof === REACT_CONSUMER_TYPE &&
error$jscomp$0(
"Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?"
);
return dispatcher.unstable_useContextWithBailout(context, select);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return resolveDispatcher().use(usable);
Expand Down Expand Up @@ -1950,7 +1942,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.1.0-www-classic-f7b1273d-20241216";
exports.version = "19.1.0-www-classic-909ed63e-20241216";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
10 changes: 1 addition & 9 deletions compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1870,14 +1870,6 @@ __DEV__ &&
exports.unstable_useCacheRefresh = function () {
return resolveDispatcher().useCacheRefresh();
};
exports.unstable_useContextWithBailout = function (context, select) {
var dispatcher = resolveDispatcher();
context.$$typeof === REACT_CONSUMER_TYPE &&
error$jscomp$0(
"Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?"
);
return dispatcher.unstable_useContextWithBailout(context, select);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return resolveDispatcher().use(usable);
Expand Down Expand Up @@ -1950,7 +1942,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.1.0-www-modern-f7b1273d-20241216";
exports.version = "19.1.0-www-modern-909ed63e-20241216";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
5 changes: 1 addition & 4 deletions compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,6 @@ exports.unstable_getCacheForType = function (resourceType) {
exports.unstable_useCacheRefresh = function () {
return ReactSharedInternals.H.useCacheRefresh();
};
exports.unstable_useContextWithBailout = function (context, select) {
return ReactSharedInternals.H.unstable_useContextWithBailout(context, select);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return ReactSharedInternals.H.use(usable);
Expand Down Expand Up @@ -633,4 +630,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-classic-f7b1273d-20241216";
exports.version = "19.1.0-www-classic-909ed63e-20241216";
5 changes: 1 addition & 4 deletions compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,6 @@ exports.unstable_getCacheForType = function (resourceType) {
exports.unstable_useCacheRefresh = function () {
return ReactSharedInternals.H.useCacheRefresh();
};
exports.unstable_useContextWithBailout = function (context, select) {
return ReactSharedInternals.H.unstable_useContextWithBailout(context, select);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return ReactSharedInternals.H.use(usable);
Expand Down Expand Up @@ -633,4 +630,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-modern-f7b1273d-20241216";
exports.version = "19.1.0-www-modern-909ed63e-20241216";
5 changes: 1 addition & 4 deletions compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,6 @@ exports.unstable_getCacheForType = function (resourceType) {
exports.unstable_useCacheRefresh = function () {
return ReactSharedInternals.H.useCacheRefresh();
};
exports.unstable_useContextWithBailout = function (context, select) {
return ReactSharedInternals.H.unstable_useContextWithBailout(context, select);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return ReactSharedInternals.H.use(usable);
Expand Down Expand Up @@ -637,7 +634,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-classic-f7b1273d-20241216";
exports.version = "19.1.0-www-classic-909ed63e-20241216";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
5 changes: 1 addition & 4 deletions compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,6 @@ exports.unstable_getCacheForType = function (resourceType) {
exports.unstable_useCacheRefresh = function () {
return ReactSharedInternals.H.useCacheRefresh();
};
exports.unstable_useContextWithBailout = function (context, select) {
return ReactSharedInternals.H.unstable_useContextWithBailout(context, select);
};
exports.unstable_useMemoCache = useMemoCache;
exports.use = function (usable) {
return ReactSharedInternals.H.use(usable);
Expand Down Expand Up @@ -637,7 +634,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-modern-f7b1273d-20241216";
exports.version = "19.1.0-www-modern-909ed63e-20241216";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
129 changes: 9 additions & 120 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3146,35 +3146,6 @@ __DEV__ &&
}
return workInProgressHook;
}
function unstable_useContextWithBailout(context, select) {
if (null === select) var JSCompiler_temp = readContext(context);
else {
JSCompiler_temp = currentlyRenderingFiber;
var value = context._currentValue2;
context = {
context: context,
memoizedValue: value,
next: null,
select: select,
lastSelectedValue: select(value)
};
if (null === lastContextDependency) {
if (null === JSCompiler_temp)
throw Error(
"Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()."
);
lastContextDependency = context;
JSCompiler_temp.dependencies = {
lanes: 0,
firstContext: context,
_debugThenableState: null
};
JSCompiler_temp.flags |= 524288;
} else lastContextDependency = lastContextDependency.next = context;
JSCompiler_temp = value;
}
return JSCompiler_temp;
}
function createFunctionComponentUpdateQueue() {
return { lastEffect: null, events: null, stores: null, memoCache: null };
}
Expand Down Expand Up @@ -8611,19 +8582,8 @@ __DEV__ &&
a: for (; null !== list; ) {
var dependency = list;
list = fiber;
var i = 0;
b: for (; i < contexts.length; i++)
for (var i = 0; i < contexts.length; i++)
if (dependency.context === contexts[i]) {
var select = dependency.select;
if (
null != select &&
null != dependency.lastSelectedValue &&
!checkIfSelectedContextValuesChanged(
dependency.lastSelectedValue,
select(dependency.context._currentValue2)
)
)
continue b;
list.lanes |= renderLanes;
dependency = list.alternate;
null !== dependency && (dependency.lanes |= renderLanes);
Expand Down Expand Up @@ -8721,37 +8681,19 @@ __DEV__ &&
);
workInProgress.flags |= 262144;
}
function checkIfSelectedContextValuesChanged(
oldComparedValue,
newComparedValue
) {
if (isArrayImpl(oldComparedValue) && isArrayImpl(newComparedValue)) {
if (oldComparedValue.length !== newComparedValue.length) return !0;
for (var i = 0; i < oldComparedValue.length; i++)
if (!objectIs(newComparedValue[i], oldComparedValue[i])) return !0;
} else throw Error("Compared context values must be arrays");
return !1;
}
function checkIfContextChanged(currentDependencies) {
for (
currentDependencies = currentDependencies.firstContext;
null !== currentDependencies;

) {
var newValue = currentDependencies.context._currentValue2,
oldValue = currentDependencies.memoizedValue;
if (
null != currentDependencies.select &&
null != currentDependencies.lastSelectedValue
) {
if (
checkIfSelectedContextValuesChanged(
currentDependencies.lastSelectedValue,
currentDependencies.select(newValue)
)
!objectIs(
currentDependencies.context._currentValue2,
currentDependencies.memoizedValue
)
return !0;
} else if (!objectIs(newValue, oldValue)) return !0;
)
return !0;
currentDependencies = currentDependencies.next;
}
return !1;
Expand Down Expand Up @@ -15150,8 +15092,6 @@ __DEV__ &&
ContextOnlyDispatcher.useEffectEvent = throwInvalidHookError;
enableUseResourceEffectHook &&
(ContextOnlyDispatcher.useResourceEffect = throwInvalidHookError);
ContextOnlyDispatcher.unstable_useContextWithBailout =
throwInvalidHookError;
var HooksDispatcherOnMountInDEV = null,
HooksDispatcherOnMountWithHookTypesInDEV = null,
HooksDispatcherOnUpdateInDEV = null,
Expand Down Expand Up @@ -15317,14 +15257,6 @@ __DEV__ &&
destroy
);
});
HooksDispatcherOnMountInDEV.unstable_useContextWithBailout = function (
context,
select
) {
currentHookNameInDev = "useContext";
mountHookTypesDev();
return unstable_useContextWithBailout(context, select);
};
HooksDispatcherOnMountWithHookTypesInDEV = {
readContext: function (context) {
return readContext(context);
Expand Down Expand Up @@ -15469,12 +15401,6 @@ __DEV__ &&
destroy
);
});
HooksDispatcherOnMountWithHookTypesInDEV.unstable_useContextWithBailout =
function (context, select) {
currentHookNameInDev = "useContext";
updateHookTypesDev();
return unstable_useContextWithBailout(context, select);
};
HooksDispatcherOnUpdateInDEV = {
readContext: function (context) {
return readContext(context);
Expand Down Expand Up @@ -15621,14 +15547,6 @@ __DEV__ &&
destroy
);
});
HooksDispatcherOnUpdateInDEV.unstable_useContextWithBailout = function (
context,
select
) {
currentHookNameInDev = "useContext";
updateHookTypesDev();
return unstable_useContextWithBailout(context, select);
};
HooksDispatcherOnRerenderInDEV = {
readContext: function (context) {
return readContext(context);
Expand Down Expand Up @@ -15775,14 +15693,6 @@ __DEV__ &&
destroy
);
});
HooksDispatcherOnRerenderInDEV.unstable_useContextWithBailout = function (
context,
select
) {
currentHookNameInDev = "useContext";
updateHookTypesDev();
return unstable_useContextWithBailout(context, select);
};
InvalidNestedHooksDispatcherOnMountInDEV = {
readContext: function (context) {
warnInvalidContextAccess();
Expand Down Expand Up @@ -15953,13 +15863,6 @@ __DEV__ &&
destroy
);
});
InvalidNestedHooksDispatcherOnMountInDEV.unstable_useContextWithBailout =
function (context, select) {
currentHookNameInDev = "useContext";
warnInvalidHookAccess();
mountHookTypesDev();
return unstable_useContextWithBailout(context, select);
};
InvalidNestedHooksDispatcherOnUpdateInDEV = {
readContext: function (context) {
warnInvalidContextAccess();
Expand Down Expand Up @@ -16132,13 +16035,6 @@ __DEV__ &&
destroy
);
});
InvalidNestedHooksDispatcherOnUpdateInDEV.unstable_useContextWithBailout =
function (context, select) {
currentHookNameInDev = "useContext";
warnInvalidHookAccess();
updateHookTypesDev();
return unstable_useContextWithBailout(context, select);
};
InvalidNestedHooksDispatcherOnRerenderInDEV = {
readContext: function (context) {
warnInvalidContextAccess();
Expand Down Expand Up @@ -16306,13 +16202,6 @@ __DEV__ &&
destroy
);
});
InvalidNestedHooksDispatcherOnRerenderInDEV.unstable_useContextWithBailout =
function (context, select) {
currentHookNameInDev = "useContext";
warnInvalidHookAccess();
updateHookTypesDev();
return unstable_useContextWithBailout(context, select);
};
var callComponent = {
"react-stack-bottom-frame": function (Component, props, secondArg) {
var wasRendering = isRendering;
Expand Down Expand Up @@ -17015,10 +16904,10 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.1.0-www-classic-f7b1273d-20241216",
version: "19.1.0-www-classic-909ed63e-20241216",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-classic-f7b1273d-20241216"
reconcilerVersion: "19.1.0-www-classic-909ed63e-20241216"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -17052,7 +16941,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.1.0-www-classic-f7b1273d-20241216";
exports.version = "19.1.0-www-classic-909ed63e-20241216";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Loading

0 comments on commit cd62d05

Please sign in to comment.