Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/react-native/React/CoreModules/RCTTiming.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <React/RCTConvert.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>

static const NSTimeInterval kMinimumSleepInterval = 1;

Expand All @@ -20,6 +21,16 @@
// The minimum time left in a frame to trigger the idle callback.
static const NSTimeInterval kIdleCallbackFrameDeadline = 0.001;

// The display link wakes the JS thread on every frame while it runs. When the
// next timer is further away than this, it is paused and a sleep timer wakes
// the JS thread when the timer is due instead. That is two frames with
// `sleepUntilNextTimerIOS`, and `kMinimumSleepInterval` otherwise.
static NSTimeInterval RCTMinimumSleepInterval()
{
return facebook::react::ReactNativeFeatureFlags::sleepUntilNextTimerIOS() ? 2 * kFrameDuration
: kMinimumSleepInterval;
}

@interface _RCTTimer : NSObject

@property (nonatomic, strong, readonly) NSDate *target;
Expand Down Expand Up @@ -284,8 +295,8 @@ - (void)didUpdateFrame:(RCTFrameUpdate *)update
if (timerCount == 0) {
_paused = YES;
}
// If the next timer is more than 1 second out, pause and schedule an NSTimer;
else if ([nextScheduledTarget timeIntervalSinceNow] > kMinimumSleepInterval) {
// If the next timer is far enough out, pause and schedule an NSTimer;
else if ([nextScheduledTarget timeIntervalSinceNow] > RCTMinimumSleepInterval()) {
[self scheduleSleepTimer:nextScheduledTarget];
_paused = YES;
}
Expand Down Expand Up @@ -347,7 +358,7 @@ - (void)createTimerForNextFrame:(nonnull NSNumber *)callbackID
if (_inBackground) {
[self scheduleSleepTimer:timer.target];
} else if (_paused) {
if ([timer.target timeIntervalSinceNow] > kMinimumSleepInterval) {
if ([timer.target timeIntervalSinceNow] > RCTMinimumSleepInterval()) {
[self scheduleSleepTimer:timer.target];
} else {
[self startTimers];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b5f4608f47743d0e2e9b1db3db551227>>
* @generated SignedSource<<dee747ba61bfdfb7a80911ddc317bef9>>
*/

/**
Expand Down Expand Up @@ -510,6 +510,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun skipUnchangedChildrenInDifferentiator(): Boolean = accessor.skipUnchangedChildrenInDifferentiator()

/**
* When the next JS timer is more than two frames away, iOS waits for it with a one-shot timer instead of a display link that wakes the JS thread on every frame until the timer is due.
*/
@JvmStatic
public fun sleepUntilNextTimerIOS(): Boolean = accessor.sleepUntilNextTimerIOS()

/**
* Override getClipBounds on Android views to return the padding box when overflow is hidden
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<d2d170d333194ce2f2a4f1d93321ac6d>>
* @generated SignedSource<<c9afbca4ee9dd0d2694fc0c4a28b74f9>>
*/

/**
Expand Down Expand Up @@ -100,6 +100,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var shouldTriggerResponderTransferOnScrollAndroidCache: Boolean? = null
private var skipActivityIdentityAssertionOnHostPauseCache: Boolean? = null
private var skipUnchangedChildrenInDifferentiatorCache: Boolean? = null
private var sleepUntilNextTimerIOSCache: Boolean? = null
private var syncAndroidClipBoundsWithOverflowCache: Boolean? = null
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
private var updateRuntimeShadowNodeReferencesOnCommitCache: Boolean? = null
Expand Down Expand Up @@ -837,6 +838,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun sleepUntilNextTimerIOS(): Boolean {
var cached = sleepUntilNextTimerIOSCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.sleepUntilNextTimerIOS()
sleepUntilNextTimerIOSCache = cached
}
return cached
}

override fun syncAndroidClipBoundsWithOverflow(): Boolean {
var cached = syncAndroidClipBoundsWithOverflowCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ec3e384af62c0e672da53b57354bca62>>
* @generated SignedSource<<24e0c997f84cabfbae228230f6ac7634>>
*/

/**
Expand Down Expand Up @@ -188,6 +188,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun skipUnchangedChildrenInDifferentiator(): Boolean

@DoNotStrip @JvmStatic public external fun sleepUntilNextTimerIOS(): Boolean

@DoNotStrip @JvmStatic public external fun syncAndroidClipBoundsWithOverflow(): Boolean

@DoNotStrip @JvmStatic public external fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<cd6aa804d1c10b93775adf83419368e3>>
* @generated SignedSource<<1185e9c777d3a0cd17d268cefb7dcd5e>>
*/

/**
Expand Down Expand Up @@ -183,6 +183,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun skipUnchangedChildrenInDifferentiator(): Boolean = false

override fun sleepUntilNextTimerIOS(): Boolean = false

override fun syncAndroidClipBoundsWithOverflow(): Boolean = false

override fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c36b0b2d7173aa78b7cb175658fc89d2>>
* @generated SignedSource<<c1c11efd3072b053ef64fe93272842fd>>
*/

/**
Expand Down Expand Up @@ -104,6 +104,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var shouldTriggerResponderTransferOnScrollAndroidCache: Boolean? = null
private var skipActivityIdentityAssertionOnHostPauseCache: Boolean? = null
private var skipUnchangedChildrenInDifferentiatorCache: Boolean? = null
private var sleepUntilNextTimerIOSCache: Boolean? = null
private var syncAndroidClipBoundsWithOverflowCache: Boolean? = null
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
private var updateRuntimeShadowNodeReferencesOnCommitCache: Boolean? = null
Expand Down Expand Up @@ -921,6 +922,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun sleepUntilNextTimerIOS(): Boolean {
var cached = sleepUntilNextTimerIOSCache
if (cached == null) {
cached = currentProvider.sleepUntilNextTimerIOS()
accessedFeatureFlags.add("sleepUntilNextTimerIOS")
sleepUntilNextTimerIOSCache = cached
}
return cached
}

override fun syncAndroidClipBoundsWithOverflow(): Boolean {
var cached = syncAndroidClipBoundsWithOverflowCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c5e9b41b76c5580c0a4ba848af4e36a5>>
* @generated SignedSource<<8e293c96cb85a664164ba5e9b67b3053>>
*/

/**
Expand Down Expand Up @@ -183,6 +183,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun skipUnchangedChildrenInDifferentiator(): Boolean

@DoNotStrip public fun sleepUntilNextTimerIOS(): Boolean

@DoNotStrip public fun syncAndroidClipBoundsWithOverflow(): Boolean

@DoNotStrip public fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1ab2eec7b9c5bdd181ec5fbfd37149ab>>
* @generated SignedSource<<b3a117e2bb71b8605481444003a9a019>>
*/

/**
Expand Down Expand Up @@ -519,6 +519,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool sleepUntilNextTimerIOS() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("sleepUntilNextTimerIOS");
return method(javaProvider_);
}

bool syncAndroidClipBoundsWithOverflow() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("syncAndroidClipBoundsWithOverflow");
Expand Down Expand Up @@ -1019,6 +1025,11 @@ bool JReactNativeFeatureFlagsCxxInterop::skipUnchangedChildrenInDifferentiator(
return ReactNativeFeatureFlags::skipUnchangedChildrenInDifferentiator();
}

bool JReactNativeFeatureFlagsCxxInterop::sleepUntilNextTimerIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::sleepUntilNextTimerIOS();
}

bool JReactNativeFeatureFlagsCxxInterop::syncAndroidClipBoundsWithOverflow(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::syncAndroidClipBoundsWithOverflow();
Expand Down Expand Up @@ -1370,6 +1381,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"skipUnchangedChildrenInDifferentiator",
JReactNativeFeatureFlagsCxxInterop::skipUnchangedChildrenInDifferentiator),
makeNativeMethod(
"sleepUntilNextTimerIOS",
JReactNativeFeatureFlagsCxxInterop::sleepUntilNextTimerIOS),
makeNativeMethod(
"syncAndroidClipBoundsWithOverflow",
JReactNativeFeatureFlagsCxxInterop::syncAndroidClipBoundsWithOverflow),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2c8f9205f1de55591ede3845ba2fa877>>
* @generated SignedSource<<bfc837c8c4654d18eea368f09600785e>>
*/

/**
Expand Down Expand Up @@ -270,6 +270,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool skipUnchangedChildrenInDifferentiator(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool sleepUntilNextTimerIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool syncAndroidClipBoundsWithOverflow(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7542508e6a3b0dd942557748186527b3>>
* @generated SignedSource<<a9eaf2ab8617efcad4e37df6510b9664>>
*/

/**
Expand Down Expand Up @@ -346,6 +346,10 @@ bool ReactNativeFeatureFlags::skipUnchangedChildrenInDifferentiator() {
return getAccessor().skipUnchangedChildrenInDifferentiator();
}

bool ReactNativeFeatureFlags::sleepUntilNextTimerIOS() {
return getAccessor().sleepUntilNextTimerIOS();
}

bool ReactNativeFeatureFlags::syncAndroidClipBoundsWithOverflow() {
return getAccessor().syncAndroidClipBoundsWithOverflow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e3c3ccaf63fcdcf48c6f02f793f77b65>>
* @generated SignedSource<<a0456bd8a91a60c80f55be11dbce2603>>
*/

/**
Expand Down Expand Up @@ -441,6 +441,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool skipUnchangedChildrenInDifferentiator();

/**
* When the next JS timer is more than two frames away, iOS waits for it with a one-shot timer instead of a display link that wakes the JS thread on every frame until the timer is due.
*/
RN_EXPORT static bool sleepUntilNextTimerIOS();

/**
* Override getClipBounds on Android views to return the padding box when overflow is hidden
*/
Expand Down
Loading
Loading