setInterval() using adjusted duration indefinitely
Description
The timer API implementations want to adjust the initial delay to take into account the time it took for the registration call to arrive from JS to the native side.
It seems that on Android, in the case of a repeating timer (setInterval), the adjusted duration is used for all repeated ticks instead of just the initial one:
https://github.com/facebook/react-native/blob/657c48c21de496734716ed33c9e55d8baae3494f/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java#L345
The effect of this is that if during the time when setInterval is invoked, something is happening in the process that's slowing down the calls to the native timer implementation, the required delay adjustment will be significant, and will cause all subsequent interval ticks to fire too quickly.
The change seems to have been introduced in f054928124a2308b2bd450acf8bb754a92ccb16a.
Version
0.65.1
Output of react-native info
System: OS: Windows 10 10.0.19042 CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz Memory: 4.83 GB / 15.76 GB Binaries: Node: 14.18.0 - C:\Program Files\nodejs\node.EXE Yarn: Not Found npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Version 2020.3.0.0 AI-203.7717.56.2031.7678000 Visual Studio: Not Found Languages: Java: 11.0.12 - C:\Program Files\Amazon Corretto\jdk11.0.12_7\bin\javac.EXE npmPackages: @react-native-community/cli: 6.0.0 => 6.0.0 react: 17.0.2 => 17.0.2 react-native: 0.65.1 => 0.65.1 react-native-windows: 0.65.1 => 0.65.1 npmGlobalPackages: react-native: Not Found
Steps to reproduce
Invoke setInterval() with a delay of 1000 while the process is very busy doing other things.
Expected: The given interval function to be invoked every 1000ms. Actual: The given interval function is invoked much more quickly.
Snack, code example, screenshot, or link to a repository
No response
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue is still valid. (Commenting to keep the issue from being closed as stale.)
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.