From d54c25fdaee4d2642cdbca812b61c6973d3f203d Mon Sep 17 00:00:00 2001 From: Anatoliy Magda <40770513+aamagda@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:49:10 -0700 Subject: [PATCH] Improve FpsDebugFrameCallback.getTotalTimeMS accuracy (#46869) Summary: `FpsDebugFrameCallback.getTotalTimeMS()` implementation loses accuracy due to incorrect order of type casting to int ## Changelog: [ANDROID] [CHANGED] - Improve FpsDebugFrameCallback.getTotalTimeMS() accuracy Pull Request resolved: https://github.com/facebook/react-native/pull/46869 Test Plan: - Launch some test app - Open up the [Dev Menu](https://reactnative.dev/docs/debugging#accessing-the-dev-menu) in your app and toggle Show Perf Monitor - Compare results of current & improved implementations Reviewed By: rshest Differential Revision: D64024054 Pulled By: arushikesarwani94 fbshipit-source-id: 438792bace0e3443d151cf13364f6e94b66dfb5e --- .../com/facebook/react/modules/debug/FpsDebugFrameCallback.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.kt index fd5b5420fcf..b36322f3754 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.kt @@ -144,7 +144,7 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) : public fun get4PlusFrameStutters(): Int = fourPlusFrameStutters public val totalTimeMS: Int - get() = (lastFrameTime.toDouble() - firstFrameTime).toInt() / 1000000 + get() = ((lastFrameTime.toDouble() - firstFrameTime) / 1000000.0).toInt() /** * Returns the FpsInfo as if stop had been called at the given upToTimeMs. Only valid if