@samitouri / QOS-React / commits / 779a472b09

Prevent inlining into recursive commit functions (#20105)

Adds a bunch of no-inline directives to commit phase functions to prevent them from being inlined into one of our recursive algorithms. The motivation is to minimize the number of variables in the recursive functions, since each one contributes to the size of the stack frame. Theoretically, this could help the performance of both the recursive and non-recursive (iterative) implementations of the commit phase, since even the iterative implementation sometimes uses the JS stack.

Andrew Clark committed Oct 27, 2020 at 14:51 UTC 779a472b0901b2d28e382f3850b2ad09a555b014
1 file changed +13
packages/react-reconciler/src/ReactFiberCommitWork.new.js
+13
@@ -212,6 +212,7 @@ function safelyCallComponentWillUnmount(
212 }
213 }
214
215 +/** @noinline */
216 function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber) {
217 const ref = current.ref;
218 if (ref !== null) {
@@ -279,6 +280,7 @@ export function safelyCallDestroy(
280 }
281 }
282
283 +/** @noinline */
284 function commitHookEffectListUnmount(
285 flags: HookFlags,
286 finishedWork: Fiber,
@@ -303,6 +305,7 @@ function commitHookEffectListUnmount(
305 }
306 }
307
308 +/** @noinline */
309 function commitHookEffectListMount(flags: HookFlags, finishedWork: Fiber) {
310 const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
311 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
@@ -512,6 +515,7 @@ function iterativelyCommitBeforeMutationEffects_complete() {
515 }
516 }
517
518 +/** @noinline */
519 function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
520 const current = finishedWork.alternate;
521 const flags = finishedWork.flags;
@@ -627,6 +631,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
631 }
632 }
633
634 +/** @noinline */
635 function commitBeforeMutationEffectsDeletions(deletions: Array<Fiber>) {
636 for (let i = 0; i < deletions.length; i++) {
637 const fiber = deletions[i];
@@ -778,6 +783,7 @@ function iterativelyCommitMutationEffects_complete(
783 }
784 }
785
786 +/** @noinline */
787 function commitMutationEffectsOnFiber(
788 fiber: Fiber,
789 root: FiberRoot,
@@ -848,6 +854,7 @@ function commitMutationEffectsOnFiber(
854 }
855 }
856
857 +/** @noinline */
858 function commitMutationEffectsDeletions(
859 deletions: Array<Fiber>,
860 nearestMountedAncestor: Fiber,
@@ -1342,6 +1349,7 @@ function commitLayoutEffectsOnFiber(
1349 }
1350 }
1351
1352 +/** @noinline */
1353 function commitLayoutEffectsForProfiler(
1354 finishedWork: Fiber,
1355 finishedRoot: FiberRoot,
@@ -1407,6 +1415,7 @@ function commitLayoutEffectsForProfiler(
1415 }
1416 }
1417
1418 +/** @noinline */
1419 function commitLayoutEffectsForClassComponent(finishedWork: Fiber) {
1420 const instance = finishedWork.stateNode;
1421 const current = finishedWork.alternate;
@@ -1555,6 +1564,7 @@ function commitLayoutEffectsForClassComponent(finishedWork: Fiber) {
1564 }
1565 }
1566
1567 +/** @noinline */
1568 function commitLayoutEffectsForHostRoot(finishedWork: Fiber) {
1569 // TODO: I think this is now always non-null by the time it reaches the
1570 // commit phase. Consider removing the type check.
@@ -1575,6 +1585,7 @@ function commitLayoutEffectsForHostRoot(finishedWork: Fiber) {
1585 }
1586 }
1587
1588 +/** @noinline */
1589 function commitLayoutEffectsForHostComponent(finishedWork: Fiber) {
1590 const instance: Instance = finishedWork.stateNode;
1591 const current = finishedWork.alternate;
@@ -1590,6 +1601,7 @@ function commitLayoutEffectsForHostComponent(finishedWork: Fiber) {
1601 }
1602 }
1603
1604 +/** @noinline */
1605 function hideOrUnhideAllChildren(finishedWork, isHidden) {
1606 if (supportsMutation) {
1607 // We only have the top Fiber that was inserted but we need to recurse down its
@@ -2950,6 +2962,7 @@ function commitSuspenseComponent(finishedWork: Fiber) {
2962 }
2963 }
2964
2965 +/** @noinline */
2966 function commitSuspenseHydrationCallbacks(
2967 finishedRoot: FiberRoot,
2968 finishedWork: Fiber,