Skip to content

Commit 779a472

Browse files
authored
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.
1 parent 25b18d3 commit 779a472

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ function safelyCallComponentWillUnmount(
212212
}
213213
}
214214

215+
/** @noinline */
215216
function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber) {
216217
const ref = current.ref;
217218
if (ref !== null) {
@@ -279,6 +280,7 @@ export function safelyCallDestroy(
279280
}
280281
}
281282

283+
/** @noinline */
282284
function commitHookEffectListUnmount(
283285
flags: HookFlags,
284286
finishedWork: Fiber,
@@ -303,6 +305,7 @@ function commitHookEffectListUnmount(
303305
}
304306
}
305307

308+
/** @noinline */
306309
function commitHookEffectListMount(flags: HookFlags, finishedWork: Fiber) {
307310
const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
308311
const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
@@ -512,6 +515,7 @@ function iterativelyCommitBeforeMutationEffects_complete() {
512515
}
513516
}
514517

518+
/** @noinline */
515519
function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
516520
const current = finishedWork.alternate;
517521
const flags = finishedWork.flags;
@@ -627,6 +631,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
627631
}
628632
}
629633

634+
/** @noinline */
630635
function commitBeforeMutationEffectsDeletions(deletions: Array<Fiber>) {
631636
for (let i = 0; i < deletions.length; i++) {
632637
const fiber = deletions[i];
@@ -778,6 +783,7 @@ function iterativelyCommitMutationEffects_complete(
778783
}
779784
}
780785

786+
/** @noinline */
781787
function commitMutationEffectsOnFiber(
782788
fiber: Fiber,
783789
root: FiberRoot,
@@ -848,6 +854,7 @@ function commitMutationEffectsOnFiber(
848854
}
849855
}
850856

857+
/** @noinline */
851858
function commitMutationEffectsDeletions(
852859
deletions: Array<Fiber>,
853860
nearestMountedAncestor: Fiber,
@@ -1342,6 +1349,7 @@ function commitLayoutEffectsOnFiber(
13421349
}
13431350
}
13441351

1352+
/** @noinline */
13451353
function commitLayoutEffectsForProfiler(
13461354
finishedWork: Fiber,
13471355
finishedRoot: FiberRoot,
@@ -1407,6 +1415,7 @@ function commitLayoutEffectsForProfiler(
14071415
}
14081416
}
14091417

1418+
/** @noinline */
14101419
function commitLayoutEffectsForClassComponent(finishedWork: Fiber) {
14111420
const instance = finishedWork.stateNode;
14121421
const current = finishedWork.alternate;
@@ -1555,6 +1564,7 @@ function commitLayoutEffectsForClassComponent(finishedWork: Fiber) {
15551564
}
15561565
}
15571566

1567+
/** @noinline */
15581568
function commitLayoutEffectsForHostRoot(finishedWork: Fiber) {
15591569
// TODO: I think this is now always non-null by the time it reaches the
15601570
// commit phase. Consider removing the type check.
@@ -1575,6 +1585,7 @@ function commitLayoutEffectsForHostRoot(finishedWork: Fiber) {
15751585
}
15761586
}
15771587

1588+
/** @noinline */
15781589
function commitLayoutEffectsForHostComponent(finishedWork: Fiber) {
15791590
const instance: Instance = finishedWork.stateNode;
15801591
const current = finishedWork.alternate;
@@ -1590,6 +1601,7 @@ function commitLayoutEffectsForHostComponent(finishedWork: Fiber) {
15901601
}
15911602
}
15921603

1604+
/** @noinline */
15931605
function hideOrUnhideAllChildren(finishedWork, isHidden) {
15941606
if (supportsMutation) {
15951607
// We only have the top Fiber that was inserted but we need to recurse down its
@@ -2950,6 +2962,7 @@ function commitSuspenseComponent(finishedWork: Fiber) {
29502962
}
29512963
}
29522964

2965+
/** @noinline */
29532966
function commitSuspenseHydrationCallbacks(
29542967
finishedRoot: FiberRoot,
29552968
finishedWork: Fiber,

0 commit comments

Comments
 (0)