@samitouri / QOS-React / commits / 7268d97d2b

Centralize props memoization (#13900)

* Move memoizedProps to after beginWork remove memoizeProps helper We always call this at the end. This is now enforced to line up since we do the equality check in the beginning of beginWork. So we can't have special cases. * Inline the one caller of memoizeState

Sebastian Markbåge committed Oct 19, 2018 at 20:12 UTC 7268d97d2b2b595db24cb6210e535dd2bd421df2
2 files changed +4 -35
packages/react-reconciler/src/ReactFiberBeginWork.js
+2 -35
@@ -230,7 +230,6 @@ function updateForwardRef(
230 nextChildren,
231 renderExpirationTime,
232 );
233 - memoizeProps(workInProgress, nextProps);
233 return workInProgress.child;
234 }
235
@@ -282,7 +281,6 @@ function updatePureComponent(
281 nextChildren,
282 renderExpirationTime,
283 );
285 - memoizeProps(workInProgress, nextProps);
284 return workInProgress.child;
285 }
286
@@ -298,7 +296,6 @@ function updateFragment(
296 nextChildren,
297 renderExpirationTime,
298 );
301 - memoizeProps(workInProgress, nextChildren);
299 return workInProgress.child;
300 }
301
@@ -314,7 +311,6 @@ function updateMode(
311 nextChildren,
312 renderExpirationTime,
313 );
317 - memoizeProps(workInProgress, nextChildren);
314 return workInProgress.child;
315 }
316
@@ -334,7 +330,6 @@ function updateProfiler(
330 nextChildren,
331 renderExpirationTime,
332 );
337 - memoizeProps(workInProgress, nextProps);
333 return workInProgress.child;
334 }
335
@@ -378,7 +373,6 @@ function updateFunctionComponent(
373 nextChildren,
374 renderExpirationTime,
375 );
381 - memoizeProps(workInProgress, nextProps);
376 return workInProgress.child;
377 }
378
@@ -539,10 +533,9 @@ function finishClassComponent(
533 );
534 }
535
542 - // Memoize props and state using the values we just used to render.
536 + // Memoize state using the values we just used to render.
537 // TODO: Restructure so we never read values from the instance.
544 - memoizeState(workInProgress, instance.state);
545 - memoizeProps(workInProgress, instance.props);
538 + workInProgress.memoizedState = instance.state;
539
540 // The context might have changed so we need to recalculate it.
541 if (hasContext) {
@@ -676,7 +669,6 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {
669 ) {
670 // Schedule this fiber to re-render at offscreen priority. Then bailout.
671 workInProgress.expirationTime = Never;
679 - workInProgress.memoizedProps = nextProps;
672 return null;
673 }
674
@@ -686,7 +678,6 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {
678 nextChildren,
679 renderExpirationTime,
680 );
689 - memoizeProps(workInProgress, nextProps);
681 return workInProgress.child;
682 }
683
@@ -694,8 +685,6 @@ function updateHostText(current, workInProgress) {
685 if (current === null) {
686 tryToClaimNextHydratableInstance(workInProgress);
687 }
697 - const nextProps = workInProgress.pendingProps;
698 - memoizeProps(workInProgress, nextProps);
688 // Nothing to do here. This is terminal. We'll do the completion step
689 // immediately after.
690 return null;
@@ -805,7 +794,6 @@ function mountIndeterminateComponent(
794 );
795 }
796 }
808 - workInProgress.memoizedProps = props;
797 return child;
798 }
799
@@ -954,7 +942,6 @@ function mountIndeterminateComponent(
942 }
943 }
944 reconcileChildren(null, workInProgress, value, renderExpirationTime);
957 - memoizeProps(workInProgress, props);
945 return workInProgress.child;
946 }
947 }
@@ -1165,7 +1152,6 @@ function updateSuspenseComponent(
1152 }
1153 }
1154
1168 - workInProgress.memoizedProps = nextProps;
1155 workInProgress.memoizedState = nextState;
1156 workInProgress.child = child;
1157 return next;
@@ -1190,7 +1176,6 @@ function updatePortalComponent(
1176 nextChildren,
1177 renderExpirationTime,
1178 );
1193 - memoizeProps(workInProgress, nextChildren);
1179 } else {
1180 reconcileChildren(
1181 current,
@@ -1198,7 +1183,6 @@ function updatePortalComponent(
1183 nextChildren,
1184 renderExpirationTime,
1185 );
1201 - memoizeProps(workInProgress, nextChildren);
1186 }
1187 return workInProgress.child;
1188 }
@@ -1215,7 +1199,6 @@ function updateContextProvider(
1199 const oldProps = workInProgress.memoizedProps;
1200
1201 const newValue = newProps.value;
1218 - workInProgress.memoizedProps = newProps;
1202
1203 if (__DEV__) {
1204 const providerPropTypes = workInProgress.type.propTypes;
@@ -1327,7 +1310,6 @@ function updateContextConsumer(
1310 // React DevTools reads this flag.
1311 workInProgress.effectTag |= PerformedWork;
1312 reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
1330 - workInProgress.memoizedProps = newProps;
1313 return workInProgress.child;
1314 }
1315
@@ -1385,17 +1367,6 @@ function bailoutOnAlreadyFinishedWork(
1367 }
1368 }
1369
1388 -// TODO: Delete memoizeProps/State and move to reconcile/bailout instead
1389 -function memoizeProps(workInProgress: Fiber, nextProps: any) {
1390 - workInProgress.memoizedProps = nextProps;
1391 -}
1392 -
1393 -function memoizeState(workInProgress: Fiber, nextState: any) {
1394 - workInProgress.memoizedState = nextState;
1395 - // Don't reset the updateQueue, in case there are pending updates. Resetting
1396 - // is handled by processUpdateQueue.
1397 -}
1398 -
1370 function beginWork(
1371 current: Fiber | null,
1372 workInProgress: Fiber,
@@ -1517,7 +1488,6 @@ function beginWork(
1488 resolveDefaultProps(Component, unresolvedProps),
1489 renderExpirationTime,
1490 );
1520 - workInProgress.memoizedProps = unresolvedProps;
1491 return child;
1492 }
1493 case ClassComponent: {
@@ -1542,7 +1512,6 @@ function beginWork(
1512 resolveDefaultProps(Component, unresolvedProps),
1513 renderExpirationTime,
1514 );
1545 - workInProgress.memoizedProps = unresolvedProps;
1515 return child;
1516 }
1517 case HostRoot:
@@ -1584,7 +1553,6 @@ function beginWork(
1553 resolveDefaultProps(Component, unresolvedProps),
1554 renderExpirationTime,
1555 );
1587 - workInProgress.memoizedProps = unresolvedProps;
1556 return child;
1557 }
1558 case Fragment:
@@ -1628,7 +1596,6 @@ function beginWork(
1596 updateExpirationTime,
1597 renderExpirationTime,
1598 );
1631 - workInProgress.memoizedProps = unresolvedProps;
1599 return child;
1600 }
1601 default:
packages/react-reconciler/src/ReactFiberScheduler.js
+2
@@ -1091,6 +1091,7 @@ function performUnitOfWork(workInProgress: Fiber): Fiber | null {
1091 }
1092
1093 next = beginWork(current, workInProgress, nextRenderExpirationTime);
1094 + workInProgress.memoizedProps = workInProgress.pendingProps;
1095
1096 if (workInProgress.mode & ProfileMode) {
1097 // Record the render duration assuming we didn't bailout (or error).
@@ -1098,6 +1099,7 @@ function performUnitOfWork(workInProgress: Fiber): Fiber | null {
1099 }
1100 } else {
1101 next = beginWork(current, workInProgress, nextRenderExpirationTime);
1102 + workInProgress.memoizedProps = workInProgress.pendingProps;
1103 }
1104
1105 if (__DEV__) {