From 0ef73f2a824919c44bb09cc6ab8e256b0e02b8ec Mon Sep 17 00:00:00 2001 From: Eric Hartzog Date: Wed, 25 May 2022 16:35:11 -0700 Subject: [PATCH] Restore early return to NativeAnimatedHelper.flushQueue Summary: Brings back a small performance win of avoiding starting/stopping a batch if the queue is empty. ## Background This was attempted previously but it happened to expose a single frame animation visual regression in VR. 1. First added in D36298399 (https://github.com/facebook/react-native/commit/55ee8ce0c4157ce5d8a95eaa60b9945b435fc988), reverted in D36378363 2. Added in a different form in D36338606 (https://github.com/facebook/react-native/commit/35e2a63b8d45a52445266bd8106600cb49081a59), reverted in D36479089 (https://github.com/facebook/react-native/commit/a4690d054ff636a15f14f086acd44656412441ec) 3. Root cause of the visual regressions introduced was fixed in D36612758 (https://github.com/facebook/react-native/commit/40f4c662bc7a66e5caea4909d74f435f5b72190c) Now that we've fixed the root cause of the visual regression, this is safe to restore. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D36670591 fbshipit-source-id: 42b6bc9c7764484f2dbb9edb122780a91b7393b4 --- Libraries/Animated/NativeAnimatedHelper.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Libraries/Animated/NativeAnimatedHelper.js b/Libraries/Animated/NativeAnimatedHelper.js index 8566df5172c..629f13ab0bb 100644 --- a/Libraries/Animated/NativeAnimatedHelper.js +++ b/Libraries/Animated/NativeAnimatedHelper.js @@ -139,6 +139,14 @@ const API = { invariant(NativeAnimatedModule, 'Native animated module is not available'); flushQueueTimeout = null; + // Early returns before calling any APIs + if (useSingleOpBatching && singleOpQueue.length === 0) { + return; + } + if (!useSingleOpBatching && queue.length === 0) { + return; + } + if (useSingleOpBatching) { // Set up event listener for callbacks if it's not set up if (