Skip to content

Commit

Permalink
[cleanup] remove deletedTreeCleanUpLevel feature flag (#25529)
Browse files Browse the repository at this point in the history
I noticed this was an experiment concluded 16 months ago (#21679) that
this extra work is beneficial
to break up cycles leaking memory in product code.

DiffTrain build for [ee85098](ee85098)
[View git log for this commit](https://github.com/facebook/react/commits/ee85098019bf9703b32f608f8bbd5f8fb1a7d60b)
  • Loading branch information
kassens committed Jan 17, 2023
1 parent 8e31656 commit a5d2d83
Show file tree
Hide file tree
Showing 28 changed files with 512 additions and 680 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4f8ffec453c41fcb6e98cb4e003f7319bb1c81b9
ee85098019bf9703b32f608f8bbd5f8fb1a7d60b
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4f8ffec453c41fcb6e98cb4e003f7319bb1c81b9
ee85098019bf9703b32f608f8bbd5f8fb1a7d60b
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-classic-4f8ffec45-20230115";
var ReactVersion = "18.3.0-www-classic-ee8509801-20230117";

// ATTENTION
// When adding new symbols to this file,
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-modern-4f8ffec45-20230115";
var ReactVersion = "18.3.0-www-modern-ee8509801-20230117";

// ATTENTION
// When adding new symbols to this file,
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,4 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-4f8ffec45-20230115";
exports.version = "18.3.0-www-classic-ee8509801-20230117";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,4 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-4f8ffec45-20230115";
exports.version = "18.3.0-www-modern-ee8509801-20230117";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-4f8ffec45-20230115";
exports.version = "18.3.0-www-classic-ee8509801-20230117";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-4f8ffec45-20230115";
exports.version = "18.3.0-www-modern-ee8509801-20230117";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
137 changes: 58 additions & 79 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-classic-4f8ffec45-20230115";
var ReactVersion = "18.3.0-www-classic-ee8509801-20230117";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -20273,55 +20273,40 @@ function detachFiberAfterEffects(fiber) {
if (alternate !== null) {
fiber.alternate = null;
detachFiberAfterEffects(alternate);
} // Note: Defensively using negation instead of < in case
// `deletedTreeCleanUpLevel` is undefined.
} // Clear cyclical Fiber fields. This level alone is designed to roughly
// approximate the planned Fiber refactor. In that world, `setState` will be
// bound to a special "instance" object instead of a Fiber. The Instance
// object will not have any of these fields. It will only be connected to
// the fiber tree via a single link at the root. So if this level alone is
// sufficient to fix memory issues, that bodes well for our plans.

{
// Clear cyclical Fiber fields. This level alone is designed to roughly
// approximate the planned Fiber refactor. In that world, `setState` will be
// bound to a special "instance" object instead of a Fiber. The Instance
// object will not have any of these fields. It will only be connected to
// the fiber tree via a single link at the root. So if this level alone is
// sufficient to fix memory issues, that bodes well for our plans.
fiber.child = null;
fiber.deletions = null;
fiber.sibling = null; // The `stateNode` is cyclical because on host nodes it points to the host
// tree, which has its own pointers to children, parents, and siblings.
// The other host nodes also point back to fibers, so we should detach that
// one, too.
fiber.child = null;
fiber.deletions = null;
fiber.sibling = null; // The `stateNode` is cyclical because on host nodes it points to the host
// tree, which has its own pointers to children, parents, and siblings.
// The other host nodes also point back to fibers, so we should detach that
// one, too.

if (fiber.tag === HostComponent) {
var hostInstance = fiber.stateNode;
}
if (fiber.tag === HostComponent) {
var hostInstance = fiber.stateNode;
}

fiber.stateNode = null; // I'm intentionally not clearing the `return` field in this level. We
// already disconnect the `return` pointer at the root of the deleted
// subtree (in `detachFiberMutation`). Besides, `return` by itself is not
// cyclical — it's only cyclical when combined with `child`, `sibling`, and
// `alternate`. But we'll clear it in the next level anyway, just in case.
fiber.stateNode = null;

{
fiber._debugOwner = null;
}
{
fiber._debugOwner = null;
} // Theoretically, nothing in here should be necessary, because we already
// disconnected the fiber from the tree. So even if something leaks this
// particular fiber, it won't leak anything else.

{
// Theoretically, nothing in here should be necessary, because we already
// disconnected the fiber from the tree. So even if something leaks this
// particular fiber, it won't leak anything else
//
// The purpose of this branch is to be super aggressive so we can measure
// if there's any difference in memory impact. If there is, that could
// indicate a React leak we don't know about.
fiber.return = null;
fiber.dependencies = null;
fiber.memoizedProps = null;
fiber.memoizedState = null;
fiber.pendingProps = null;
fiber.stateNode = null; // TODO: Move to `commitPassiveUnmountInsideDeletedTreeOnFiber` instead.
fiber.return = null;
fiber.dependencies = null;
fiber.memoizedProps = null;
fiber.memoizedState = null;
fiber.pendingProps = null;
fiber.stateNode = null; // TODO: Move to `commitPassiveUnmountInsideDeletedTreeOnFiber` instead.

fiber.updateQueue = null;
}
}
fiber.updateQueue = null;
}

function getHostParentFiber(fiber) {
Expand Down Expand Up @@ -22398,33 +22383,31 @@ function commitPassiveUnmountEffects(finishedWork) {
}

function detachAlternateSiblings(parentFiber) {
{
// A fiber was deleted from this parent fiber, but it's still part of the
// previous (alternate) parent fiber's list of children. Because children
// are a linked list, an earlier sibling that's still alive will be
// connected to the deleted fiber via its `alternate`:
//
// live fiber --alternate--> previous live fiber --sibling--> deleted
// fiber
//
// We can't disconnect `alternate` on nodes that haven't been deleted yet,
// but we can disconnect the `sibling` and `child` pointers.
var previousFiber = parentFiber.alternate;
// A fiber was deleted from this parent fiber, but it's still part of the
// previous (alternate) parent fiber's list of children. Because children
// are a linked list, an earlier sibling that's still alive will be
// connected to the deleted fiber via its `alternate`:
//
// live fiber --alternate--> previous live fiber --sibling--> deleted
// fiber
//
// We can't disconnect `alternate` on nodes that haven't been deleted yet,
// but we can disconnect the `sibling` and `child` pointers.
var previousFiber = parentFiber.alternate;

if (previousFiber !== null) {
var detachedChild = previousFiber.child;
if (previousFiber !== null) {
var detachedChild = previousFiber.child;

if (detachedChild !== null) {
previousFiber.child = null;
if (detachedChild !== null) {
previousFiber.child = null;

do {
// $FlowFixMe[incompatible-use] found when upgrading Flow
var detachedSibling = detachedChild.sibling; // $FlowFixMe[incompatible-use] found when upgrading Flow
do {
// $FlowFixMe[incompatible-use] found when upgrading Flow
var detachedSibling = detachedChild.sibling; // $FlowFixMe[incompatible-use] found when upgrading Flow

detachedChild.sibling = null;
detachedChild = detachedSibling;
} while (detachedChild !== null);
}
detachedChild.sibling = null;
detachedChild = detachedSibling;
} while (detachedChild !== null);
}
}
}
Expand Down Expand Up @@ -22617,8 +22600,7 @@ function commitPassiveUnmountEffectsInsideOfDeletedTree_begin(
setCurrentFiber(fiber);
commitPassiveUnmountInsideDeletedTreeOnFiber(fiber, nearestMountedAncestor);
resetCurrentFiber();
var child = fiber.child; // TODO: Only traverse subtree if it has a PassiveStatic flag. (But, if we
// do this, still need to handle `deletedTreeCleanUpLevel` correctly.)
var child = fiber.child; // TODO: Only traverse subtree if it has a PassiveStatic flag.

if (child !== null) {
child.return = fiber;
Expand All @@ -22637,18 +22619,15 @@ function commitPassiveUnmountEffectsInsideOfDeletedTree_complete(
while (nextEffect !== null) {
var fiber = nextEffect;
var sibling = fiber.sibling;
var returnFiber = fiber.return;
var returnFiber = fiber.return; // Recursively traverse the entire deleted tree and clean up fiber fields.
// This is more aggressive than ideal, and the long term goal is to only
// have to detach the deleted tree at the root.

{
// Recursively traverse the entire deleted tree and clean up fiber fields.
// This is more aggressive than ideal, and the long term goal is to only
// have to detach the deleted tree at the root.
detachFiberAfterEffects(fiber);
detachFiberAfterEffects(fiber);

if (fiber === deletedSubtreeRoot) {
nextEffect = null;
return;
}
if (fiber === deletedSubtreeRoot) {
nextEffect = null;
return;
}

if (sibling !== null) {
Expand Down
Loading

0 comments on commit a5d2d83

Please sign in to comment.