Skip to content

Commit 4e6493a

Browse files
committed
Make class prop resolution faster (#28766)
`delete` causes an object (in V8, and maybe other engines) to deopt to a dictionary instead of a class. Instead of `assign` + `delete`, manually iterate over all the properties, like the JSX runtime does. To avoid copying the object twice I moved the `ref` prop removal to come before handling default props. If we already cloned the props to remove `ref`, then we can skip cloning again to handle default props. DiffTrain build for commit bfd8da8.
1 parent 6eddd13 commit 4e6493a

File tree

10 files changed

+58
-46
lines changed

10 files changed

+58
-46
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<fa29b2fc6de1e6452849c40ebd890ad7>>
10+
* @generated SignedSource<<5dd37abeea74ddd8ec0ebe6450152a2d>>
1111
*/
1212

1313
"use strict";
@@ -12999,7 +12999,7 @@ if (__DEV__) {
1299912999
// remove this extra check.
1300013000
alreadyResolvedDefaultProps
1300113001
) {
13002-
var newProps = baseProps; // Resolve default props. Taken from old JSX runtime, where this used to live.
13002+
var newProps = baseProps;
1300313003

1300413004
var defaultProps = Component.defaultProps;
1300513005

@@ -13008,11 +13008,15 @@ if (__DEV__) {
1300813008
// default props here in the reconciler, rather than in the JSX runtime.
1300913009
!alreadyResolvedDefaultProps
1301013010
) {
13011-
newProps = assign({}, newProps, baseProps);
13011+
// We may have already copied the props object above to remove ref. If so,
13012+
// we can modify that. Otherwise, copy the props object with Object.assign.
13013+
if (newProps === baseProps) {
13014+
newProps = assign({}, newProps, baseProps);
13015+
} // Taken from old JSX runtime, where this used to live.
1301213016

13013-
for (var propName in defaultProps) {
13014-
if (newProps[propName] === undefined) {
13015-
newProps[propName] = defaultProps[propName];
13017+
for (var _propName in defaultProps) {
13018+
if (newProps[_propName] === undefined) {
13019+
newProps[_propName] = defaultProps[_propName];
1301613020
}
1301713021
}
1301813022
}
@@ -26620,7 +26624,7 @@ if (__DEV__) {
2662026624
return root;
2662126625
}
2662226626

26623-
var ReactVersion = "19.0.0-canary-2f991a8a";
26627+
var ReactVersion = "19.0.0-canary-dd665447";
2662426628

2662526629
/*
2662626630
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<c280d92632a452d04a57733b09d6735d>>
10+
* @generated SignedSource<<000f349e62b33714c1beb5b32a865608>>
1111
*/
1212

1313
"use strict";
@@ -3472,7 +3472,7 @@ function resolveClassComponentProps(
34723472
) {
34733473
var newProps = baseProps;
34743474
if ((Component = Component.defaultProps) && !alreadyResolvedDefaultProps) {
3475-
newProps = assign({}, newProps, baseProps);
3475+
newProps === baseProps && (newProps = assign({}, newProps, baseProps));
34763476
for (var propName in Component)
34773477
void 0 === newProps[propName] &&
34783478
(newProps[propName] = Component[propName]);
@@ -9154,7 +9154,7 @@ var devToolsConfig$jscomp$inline_994 = {
91549154
throw Error("TestRenderer does not support findFiberByHostInstance()");
91559155
},
91569156
bundleType: 0,
9157-
version: "19.0.0-canary-f92daaf1",
9157+
version: "19.0.0-canary-f60d093a",
91589158
rendererPackageName: "react-test-renderer"
91599159
};
91609160
var internals$jscomp$inline_1214 = {
@@ -9185,7 +9185,7 @@ var internals$jscomp$inline_1214 = {
91859185
scheduleRoot: null,
91869186
setRefreshHandler: null,
91879187
getCurrentFiber: null,
9188-
reconcilerVersion: "19.0.0-canary-f92daaf1"
9188+
reconcilerVersion: "19.0.0-canary-f60d093a"
91899189
};
91909190
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
91919191
var hook$jscomp$inline_1215 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<74899a6d3fe92773c2f385a9916407bb>>
10+
* @generated SignedSource<<b9d1eed3b9bd859cc782a84afe6d9a15>>
1111
*/
1212

1313
"use strict";
@@ -3630,7 +3630,7 @@ function resolveClassComponentProps(
36303630
) {
36313631
var newProps = baseProps;
36323632
if ((Component = Component.defaultProps) && !alreadyResolvedDefaultProps) {
3633-
newProps = assign({}, newProps, baseProps);
3633+
newProps === baseProps && (newProps = assign({}, newProps, baseProps));
36343634
for (var propName in Component)
36353635
void 0 === newProps[propName] &&
36363636
(newProps[propName] = Component[propName]);
@@ -9770,7 +9770,7 @@ var devToolsConfig$jscomp$inline_1078 = {
97709770
throw Error("TestRenderer does not support findFiberByHostInstance()");
97719771
},
97729772
bundleType: 0,
9773-
version: "19.0.0-canary-aa699661",
9773+
version: "19.0.0-canary-461e8e8d",
97749774
rendererPackageName: "react-test-renderer"
97759775
};
97769776
(function (internals) {
@@ -9814,7 +9814,7 @@ var devToolsConfig$jscomp$inline_1078 = {
98149814
scheduleRoot: null,
98159815
setRefreshHandler: null,
98169816
getCurrentFiber: null,
9817-
reconcilerVersion: "19.0.0-canary-aa699661"
9817+
reconcilerVersion: "19.0.0-canary-461e8e8d"
98189818
});
98199819
exports._Scheduler = Scheduler;
98209820
exports.act = act;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f33a6b69c6cb406ea0cc51d07bc4d3fd2d8d8744
1+
bfd8da807c75a2d123627415f9eaf2d36ac3ed6a

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<5dd386bf9cd76540dc618bfac3e54671>>
10+
* @generated SignedSource<<4a4d1580791e4b04df69f1d39838d86e>>
1111
*/
1212

1313
"use strict";
@@ -16552,7 +16552,7 @@ to return true:wantsResponderID| |
1655216552
// remove this extra check.
1655316553
alreadyResolvedDefaultProps
1655416554
) {
16555-
var newProps = baseProps; // Resolve default props. Taken from old JSX runtime, where this used to live.
16555+
var newProps = baseProps;
1655616556

1655716557
var defaultProps = Component.defaultProps;
1655816558

@@ -16561,11 +16561,15 @@ to return true:wantsResponderID| |
1656116561
// default props here in the reconciler, rather than in the JSX runtime.
1656216562
(disableDefaultPropsExceptForClasses || !alreadyResolvedDefaultProps)
1656316563
) {
16564-
newProps = assign({}, newProps, baseProps);
16564+
// We may have already copied the props object above to remove ref. If so,
16565+
// we can modify that. Otherwise, copy the props object with Object.assign.
16566+
if (newProps === baseProps) {
16567+
newProps = assign({}, newProps, baseProps);
16568+
} // Taken from old JSX runtime, where this used to live.
1656516569

16566-
for (var propName in defaultProps) {
16567-
if (newProps[propName] === undefined) {
16568-
newProps[propName] = defaultProps[propName];
16570+
for (var _propName in defaultProps) {
16571+
if (newProps[_propName] === undefined) {
16572+
newProps[_propName] = defaultProps[_propName];
1656916573
}
1657016574
}
1657116575
}
@@ -30314,7 +30318,7 @@ to return true:wantsResponderID| |
3031430318
return root;
3031530319
}
3031630320

30317-
var ReactVersion = "19.0.0-canary-2c2952e8";
30321+
var ReactVersion = "19.0.0-canary-86741a5e";
3031830322

3031930323
/*
3032030324
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<54298e069f406267149c6223a3e091da>>
10+
* @generated SignedSource<<40b9e8d1940ea7c4aa128e958d245bc0>>
1111
*/
1212

1313
"use strict";
@@ -5018,7 +5018,7 @@ function resolveClassComponentProps(
50185018
(Component = Component.defaultProps) &&
50195019
(disableDefaultPropsExceptForClasses || !alreadyResolvedDefaultProps)
50205020
) {
5021-
newProps = assign({}, newProps, baseProps);
5021+
newProps === baseProps && (newProps = assign({}, newProps, baseProps));
50225022
for (var propName in Component)
50235023
void 0 === newProps[propName] &&
50245024
(newProps[propName] = Component[propName]);
@@ -10584,7 +10584,7 @@ var roots = new Map(),
1058410584
devToolsConfig$jscomp$inline_1095 = {
1058510585
findFiberByHostInstance: getInstanceFromNode,
1058610586
bundleType: 0,
10587-
version: "19.0.0-canary-dd9880b4",
10587+
version: "19.0.0-canary-01f2d6f5",
1058810588
rendererPackageName: "react-native-renderer",
1058910589
rendererConfig: {
1059010590
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10627,7 +10627,7 @@ var internals$jscomp$inline_1364 = {
1062710627
scheduleRoot: null,
1062810628
setRefreshHandler: null,
1062910629
getCurrentFiber: null,
10630-
reconcilerVersion: "19.0.0-canary-dd9880b4"
10630+
reconcilerVersion: "19.0.0-canary-01f2d6f5"
1063110631
};
1063210632
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1063310633
var hook$jscomp$inline_1365 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<abdef96f99146c2621cf22ff704541f5>>
10+
* @generated SignedSource<<20b7d465c184525ed91fa85c2d27663d>>
1111
*/
1212

1313
"use strict";
@@ -5210,7 +5210,7 @@ function resolveClassComponentProps(
52105210
(Component = Component.defaultProps) &&
52115211
(disableDefaultPropsExceptForClasses || !alreadyResolvedDefaultProps)
52125212
) {
5213-
newProps = assign({}, newProps, baseProps);
5213+
newProps === baseProps && (newProps = assign({}, newProps, baseProps));
52145214
for (var propName in Component)
52155215
void 0 === newProps[propName] &&
52165216
(newProps[propName] = Component[propName]);
@@ -11289,7 +11289,7 @@ var roots = new Map(),
1128911289
devToolsConfig$jscomp$inline_1177 = {
1129011290
findFiberByHostInstance: getInstanceFromNode,
1129111291
bundleType: 0,
11292-
version: "19.0.0-canary-da67beca",
11292+
version: "19.0.0-canary-4fe4467c",
1129311293
rendererPackageName: "react-native-renderer",
1129411294
rendererConfig: {
1129511295
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11345,7 +11345,7 @@ var roots = new Map(),
1134511345
scheduleRoot: null,
1134611346
setRefreshHandler: null,
1134711347
getCurrentFiber: null,
11348-
reconcilerVersion: "19.0.0-canary-da67beca"
11348+
reconcilerVersion: "19.0.0-canary-4fe4467c"
1134911349
});
1135011350
exports.createPortal = function (children, containerTag) {
1135111351
return createPortal$1(

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<50a9b99ec068577f4323f59c87924a6b>>
10+
* @generated SignedSource<<c73a551f4a3130c37086d7107a16668b>>
1111
*/
1212

1313
"use strict";
@@ -16823,7 +16823,7 @@ to return true:wantsResponderID| |
1682316823
// remove this extra check.
1682416824
alreadyResolvedDefaultProps
1682516825
) {
16826-
var newProps = baseProps; // Resolve default props. Taken from old JSX runtime, where this used to live.
16826+
var newProps = baseProps;
1682716827

1682816828
var defaultProps = Component.defaultProps;
1682916829

@@ -16832,11 +16832,15 @@ to return true:wantsResponderID| |
1683216832
// default props here in the reconciler, rather than in the JSX runtime.
1683316833
(disableDefaultPropsExceptForClasses || !alreadyResolvedDefaultProps)
1683416834
) {
16835-
newProps = assign({}, newProps, baseProps);
16835+
// We may have already copied the props object above to remove ref. If so,
16836+
// we can modify that. Otherwise, copy the props object with Object.assign.
16837+
if (newProps === baseProps) {
16838+
newProps = assign({}, newProps, baseProps);
16839+
} // Taken from old JSX runtime, where this used to live.
1683616840

16837-
for (var propName in defaultProps) {
16838-
if (newProps[propName] === undefined) {
16839-
newProps[propName] = defaultProps[propName];
16841+
for (var _propName in defaultProps) {
16842+
if (newProps[_propName] === undefined) {
16843+
newProps[_propName] = defaultProps[_propName];
1684016844
}
1684116845
}
1684216846
}
@@ -30754,7 +30758,7 @@ to return true:wantsResponderID| |
3075430758
return root;
3075530759
}
3075630760

30757-
var ReactVersion = "19.0.0-canary-6807d8d2";
30761+
var ReactVersion = "19.0.0-canary-4c6edcb1";
3075830762

3075930763
/*
3076030764
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<23b66786bd7f0bd71723c2bf074a88b0>>
10+
* @generated SignedSource<<a975d416ac4c7f46931f4ff8e2183f5c>>
1111
*/
1212

1313
"use strict";
@@ -5083,7 +5083,7 @@ function resolveClassComponentProps(
50835083
(Component = Component.defaultProps) &&
50845084
(disableDefaultPropsExceptForClasses || !alreadyResolvedDefaultProps)
50855085
) {
5086-
newProps = assign({}, newProps, baseProps);
5086+
newProps === baseProps && (newProps = assign({}, newProps, baseProps));
50875087
for (var propName in Component)
50885088
void 0 === newProps[propName] &&
50895089
(newProps[propName] = Component[propName]);
@@ -10800,7 +10800,7 @@ var roots = new Map(),
1080010800
devToolsConfig$jscomp$inline_1162 = {
1080110801
findFiberByHostInstance: getInstanceFromTag,
1080210802
bundleType: 0,
10803-
version: "19.0.0-canary-8d422163",
10803+
version: "19.0.0-canary-bbe25df7",
1080410804
rendererPackageName: "react-native-renderer",
1080510805
rendererConfig: {
1080610806
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10843,7 +10843,7 @@ var internals$jscomp$inline_1445 = {
1084310843
scheduleRoot: null,
1084410844
setRefreshHandler: null,
1084510845
getCurrentFiber: null,
10846-
reconcilerVersion: "19.0.0-canary-8d422163"
10846+
reconcilerVersion: "19.0.0-canary-bbe25df7"
1084710847
};
1084810848
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1084910849
var hook$jscomp$inline_1446 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<b334f048486473032d93217c6858a766>>
10+
* @generated SignedSource<<4a679b19e322c1ae35a57c741538ab4c>>
1111
*/
1212

1313
"use strict";
@@ -5275,7 +5275,7 @@ function resolveClassComponentProps(
52755275
(Component = Component.defaultProps) &&
52765276
(disableDefaultPropsExceptForClasses || !alreadyResolvedDefaultProps)
52775277
) {
5278-
newProps = assign({}, newProps, baseProps);
5278+
newProps === baseProps && (newProps = assign({}, newProps, baseProps));
52795279
for (var propName in Component)
52805280
void 0 === newProps[propName] &&
52815281
(newProps[propName] = Component[propName]);
@@ -11506,7 +11506,7 @@ var roots = new Map(),
1150611506
devToolsConfig$jscomp$inline_1244 = {
1150711507
findFiberByHostInstance: getInstanceFromTag,
1150811508
bundleType: 0,
11509-
version: "19.0.0-canary-596ee199",
11509+
version: "19.0.0-canary-d2e200b3",
1151011510
rendererPackageName: "react-native-renderer",
1151111511
rendererConfig: {
1151211512
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11562,7 +11562,7 @@ var roots = new Map(),
1156211562
scheduleRoot: null,
1156311563
setRefreshHandler: null,
1156411564
getCurrentFiber: null,
11565-
reconcilerVersion: "19.0.0-canary-596ee199"
11565+
reconcilerVersion: "19.0.0-canary-d2e200b3"
1156611566
});
1156711567
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
1156811568
computeComponentStackForErrorReporting: function (reactTag) {

0 commit comments

Comments
 (0)