Skip to content

Commit

Permalink
[Draft] Add feature flag: enableStrongMemoryCleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bgirard committed Mar 20, 2021
1 parent 00d4f95 commit ca237fc
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
enableSuspenseCallback,
enableScopeAPI,
enableStrictEffects,
enableStrongMemoryCleanup,
} from 'shared/ReactFeatureFlags';
import {
FunctionComponent,
Expand Down Expand Up @@ -1212,9 +1213,28 @@ function detachFiberMutation(fiber: Fiber) {
fiber.return = null;
}

export function detachFiberAfterEffects(fiber: Fiber): void {
export function detachFiberAfterEffects(
fiber: Fiber,
recurseIntoSibbling: ?boolean,
): void {
// Null out fields to improve GC for references that may be lingering (e.g. DevTools).
// Note that we already cleared the return pointer in detachFiberMutation().
if (enableStrongMemoryCleanup) {
if (fiber.child) {
detachFiberAfterEffects(fiber.child, true);
}
if (fiber.sibling && recurseIntoSibbling === true) {
detachFiberAfterEffects(fiber.sibling, true);
}
if (fiber.stateNode) {
Object.keys(fiber.stateNode).forEach(key => {
if (key.indexOf('__react') === 0) {
delete fiber.stateNode[key];
}
});
}
fiber.return = null;
}
fiber.alternate = null;
fiber.child = null;
fiber.deletions = null;
Expand Down
22 changes: 21 additions & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
enableSuspenseCallback,
enableScopeAPI,
enableStrictEffects,
enableStrongMemoryCleanup,
} from 'shared/ReactFeatureFlags';
import {
FunctionComponent,
Expand Down Expand Up @@ -1212,9 +1213,28 @@ function detachFiberMutation(fiber: Fiber) {
fiber.return = null;
}

export function detachFiberAfterEffects(fiber: Fiber): void {
export function detachFiberAfterEffects(
fiber: Fiber,
recurseIntoSibbling: ?boolean,
): void {
// Null out fields to improve GC for references that may be lingering (e.g. DevTools).
// Note that we already cleared the return pointer in detachFiberMutation().
if (enableStrongMemoryCleanup) {
if (fiber.child) {
detachFiberAfterEffects(fiber.child, true);
}
if (fiber.sibling && recurseIntoSibbling === true) {
detachFiberAfterEffects(fiber.sibling, true);
}
if (fiber.stateNode) {
Object.keys(fiber.stateNode).forEach(key => {
if (key.indexOf('__react') === 0) {
delete fiber.stateNode[key];
}
});
}
fiber.return = null;
}
fiber.alternate = null;
fiber.child = null;
fiber.deletions = null;
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export const disableNativeComponentFrames = false;
// If there are no still-mounted boundaries, the errors should be rethrown.
export const skipUnmountedBoundaries = false;

export const enableStrongMemoryCleanup = true;

// --------------------------
// Future APIs to be deprecated
// --------------------------
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const disableNativeComponentFrames = false;
export const skipUnmountedBoundaries = false;
export const enableStrongMemoryCleanup = true;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const disableNativeComponentFrames = false;
export const skipUnmountedBoundaries = false;
export const enableStrongMemoryCleanup = true;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const disableNativeComponentFrames = false;
export const skipUnmountedBoundaries = false;
export const enableStrongMemoryCleanup = true;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const disableNativeComponentFrames = false;
export const skipUnmountedBoundaries = false;
export const enableStrongMemoryCleanup = true;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const disableNativeComponentFrames = false;
export const skipUnmountedBoundaries = false;
export const enableStrongMemoryCleanup = true;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const disableNativeComponentFrames = false;
export const skipUnmountedBoundaries = false;
export const enableStrongMemoryCleanup = true;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const enableLegacyFBSupport = !__EXPERIMENTAL__;
export const enableFilterEmptyStringAttributesDOM = false;
export const disableNativeComponentFrames = false;
export const skipUnmountedBoundaries = true;
export const enableStrongMemoryCleanup = true;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const disableNativeComponentFrames = false;
export const createRootStrictEffectsByDefault = false;
export const enableStrictEffects = false;
export const enableUseRefAccessWarning = __VARIANT__;
export const enableStrongMemoryCleanup = __VARIANT__;

export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export const enableNewReconciler = __VARIANT__;

export const enableRecursiveCommitTraversal = false;

export const enableStrongMemoryCleanup = __VARIANT__;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
type Check<_X, Y: _X, X: Y = _X> = null;
Expand Down

0 comments on commit ca237fc

Please sign in to comment.