Skip to content

Commit

Permalink
Add feature flags for expiration times (facebook#27821)
Browse files Browse the repository at this point in the history
It seems worthwhile to me to run a test to experiment with different
expiration times. This moves the expiration times for scheduler and
reconciler into FeatureFlags for the facebook build. Non-facebook should
not be affected by these changes.
  • Loading branch information
kassens authored and AndyPengc12 committed Apr 15, 2024
1 parent 82fa9ea commit 51425aa
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 20 deletions.
11 changes: 8 additions & 3 deletions packages/react-reconciler/src/ReactFiberLane.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
enableTransitionTracing,
enableUnifiedSyncLane,
enableUpdaterTracking,
syncLaneExpirationMs,
transitionLaneExpirationMs,
retryLaneExpirationMs,
} from 'shared/ReactFeatureFlags';
import {isDevToolsPresent} from './ReactFiberDevToolsHook';
import {ConcurrentUpdatesByDefaultMode, NoMode} from './ReactTypeOfMode';
Expand Down Expand Up @@ -355,7 +358,7 @@ function computeExpirationTime(lane: Lane, currentTime: number) {
// to fix the starvation. However, this scenario supports the idea that
// expiration times are an important safeguard when starvation
// does happen.
return currentTime + 250;
return currentTime + syncLaneExpirationMs;
case DefaultHydrationLane:
case DefaultLane:
case TransitionHydrationLane:
Expand All @@ -374,7 +377,7 @@ function computeExpirationTime(lane: Lane, currentTime: number) {
case TransitionLane13:
case TransitionLane14:
case TransitionLane15:
return currentTime + 5000;
return currentTime + transitionLaneExpirationMs;
case RetryLane1:
case RetryLane2:
case RetryLane3:
Expand All @@ -384,7 +387,9 @@ function computeExpirationTime(lane: Lane, currentTime: number) {
// crashes. There must be some other underlying bug; not super urgent but
// ideally should figure out why and fix it. Unfortunately we don't have
// a repro for the crashes, only detected via production metrics.
return enableRetryLaneExpiration ? currentTime + 5000 : NoTimestamp;
return enableRetryLaneExpiration
? currentTime + retryLaneExpirationMs
: NoTimestamp;
case SelectiveHydrationLane:
case IdleHydrationLane:
case IdleLane:
Expand Down
4 changes: 4 additions & 0 deletions packages/scheduler/src/SchedulerFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export const enableIsInputPendingContinuous = false;
export const frameYieldMs = 5;
export const continuousYieldMs = 50;
export const maxYieldMs = 300;

export const userBlockingPriorityTimeout = 250;
export const normalPriorityTimeout = 5000;
export const lowPriorityTimeout = 10000;
27 changes: 13 additions & 14 deletions packages/scheduler/src/forks/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
frameYieldMs,
continuousYieldMs,
maxYieldMs,
userBlockingPriorityTimeout,
lowPriorityTimeout,
normalPriorityTimeout,
} from '../SchedulerFeatureFlags';

import {push, pop, peek} from '../SchedulerMinHeap';
Expand Down Expand Up @@ -75,15 +78,6 @@ if (hasPerformanceNow) {
// 0b111111111111111111111111111111
var maxSigned31BitInt = 1073741823;

// Times out immediately
var IMMEDIATE_PRIORITY_TIMEOUT = -1;
// Eventually times out
var USER_BLOCKING_PRIORITY_TIMEOUT = 250;
var NORMAL_PRIORITY_TIMEOUT = 5000;
var LOW_PRIORITY_TIMEOUT = 10000;
// Never times out
var IDLE_PRIORITY_TIMEOUT = maxSigned31BitInt;

// Tasks are stored on a min heap
var taskQueue: Array<Task> = [];
var timerQueue: Array<Task> = [];
Expand Down Expand Up @@ -362,20 +356,25 @@ function unstable_scheduleCallback(
var timeout;
switch (priorityLevel) {
case ImmediatePriority:
timeout = IMMEDIATE_PRIORITY_TIMEOUT;
// Times out immediately
timeout = -1;
break;
case UserBlockingPriority:
timeout = USER_BLOCKING_PRIORITY_TIMEOUT;
// Eventually times out
timeout = userBlockingPriorityTimeout;
break;
case IdlePriority:
timeout = IDLE_PRIORITY_TIMEOUT;
// Never times out
timeout = maxSigned31BitInt;
break;
case LowPriority:
timeout = LOW_PRIORITY_TIMEOUT;
// Eventually times out
timeout = lowPriorityTimeout;
break;
case NormalPriority:
default:
timeout = NORMAL_PRIORITY_TIMEOUT;
// Eventually times out
timeout = normalPriorityTimeout;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
// with the __VARIANT__ set to `true`, and once set to `false`.

export const enableProfiling = __VARIANT__;

export const userBlockingPriorityTimeout = 250;
export const normalPriorityTimeout = 5000;
export const lowPriorityTimeout = 10000;
12 changes: 9 additions & 3 deletions packages/scheduler/src/forks/SchedulerFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
* @flow
*/

const {enableProfiling: enableProfilingFeatureFlag} =
// $FlowFixMe[cannot-resolve-module]
require('SchedulerFeatureFlags');
// $FlowFixMe[cannot-resolve-module]
const dynamicFeatureFlags = require('SchedulerFeatureFlags');

const {enableProfiling: enableProfilingFeatureFlag} = dynamicFeatureFlags;

export const {
userBlockingPriorityTimeout,
normalPriorityTimeout,
lowPriorityTimeout,
} = dynamicFeatureFlags;
export const enableSchedulerDebugging = true;
export const enableProfiling: boolean =
__PROFILE__ && enableProfilingFeatureFlag;
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;
* Enables an expiration time for retry lanes to avoid starvation.
*/
export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;

// -----------------------------------------------------------------------------
// Chopping Block
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export const enableComponentStackLocations = false;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableGetInspectorDataForInstanceInProduction = true;

export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;

export const createRootStrictEffectsByDefault = false;

Expand Down
4 changes: 4 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export const enableComponentStackLocations = false;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableGetInspectorDataForInstanceInProduction = false;

export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;

export const createRootStrictEffectsByDefault = false;
export const enableUseRefAccessWarning = false;
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableGetInspectorDataForInstanceInProduction = false;

export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;

export const createRootStrictEffectsByDefault = false;
export const enableUseRefAccessWarning = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export const enableUseEffectEventHook = false;
export const enableClientRenderFallbackOnTextMismatch = true;
export const createRootStrictEffectsByDefault = false;
export const enableUseRefAccessWarning = false;

export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;

export const disableSchedulerTimeoutInWorkLoop = false;
export const enableLazyContextPropagation = false;
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = true;
export const enableGetInspectorDataForInstanceInProduction = false;

export const enableRetryLaneExpiration = false;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;

export const createRootStrictEffectsByDefault = false;
export const enableUseRefAccessWarning = false;
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export const enableAsyncActions = __VARIANT__;
export const alwaysThrottleRetries = __VARIANT__;
export const enableDO_NOT_USE_disableStrictPassiveEffect = __VARIANT__;
export const enableUseDeferredValueInitialArg = __VARIANT__;

export const enableRetryLaneExpiration = __VARIANT__;
export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;

// Enable this flag to help with concurrent mode debugging.
// It logs information to the console about React scheduling, rendering, and commit phases.
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const {
enableDO_NOT_USE_disableStrictPassiveEffect,
disableSchedulerTimeoutInWorkLoop,
enableUseDeferredValueInitialArg,
retryLaneExpirationMs,
syncLaneExpirationMs,
transitionLaneExpirationMs,
} = dynamicFeatureFlags;

// On WWW, __EXPERIMENTAL__ is used for a new modern build.
Expand Down

0 comments on commit 51425aa

Please sign in to comment.