From 55ee8ce0c4157ce5d8a95eaa60b9945b435fc988 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 12 May 2022 05:49:01 -0700 Subject: [PATCH] Check queue size before starting Animated batch Summary: Small win: if the queue is empty we shouldn't start/stop the batch. Changelog: [Internal] Reviewed By: rshest Differential Revision: D36298399 fbshipit-source-id: b43c07994ba28b4c890fe52af4e81c265a3b8ac7 --- Libraries/Animated/NativeAnimatedHelper.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Libraries/Animated/NativeAnimatedHelper.js b/Libraries/Animated/NativeAnimatedHelper.js index e97a10d262e..3588e197b51 100644 --- a/Libraries/Animated/NativeAnimatedHelper.js +++ b/Libraries/Animated/NativeAnimatedHelper.js @@ -65,16 +65,18 @@ const API = { }, disableQueue: function (): void { invariant(NativeAnimatedModule, 'Native animated module is not available'); - - if (Platform.OS === 'android') { - NativeAnimatedModule.startOperationBatch(); - } - for (let q = 0, l = queue.length; q < l; q++) { - queue[q](); - } - queue.length = 0; - if (Platform.OS === 'android') { - NativeAnimatedModule.finishOperationBatch(); + const queueLength = queue.length; + if (queueLength > 0) { + if (Platform.OS === 'android') { + NativeAnimatedModule.startOperationBatch(); + } + for (let i = 0; i < queueLength; i++) { + queue[i](); + } + queue.length = 0; + if (Platform.OS === 'android') { + NativeAnimatedModule.finishOperationBatch(); + } } }, queueOperation: (fn: () => void): void => {