From 3df0f3b9ff4cc9cd6846ef02101baf8e9605d6a0 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 5 Sep 2024 04:48:15 -0700 Subject: [PATCH] Skip transform invalidation if unchanged (#46345) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46345 Deriving transforms can be expensive on Android. When using NativeAnimated with transforms, especially with an EventBasedDriver, we may update the transform every frame, even if it's unchanged. Ideally, we'd fix this in Animated, and diff the previous and next values, but this closes the gap somewhat in the short-term. Both JavaOnlyArray and ReadableNativeArray implement equals, but will not compare equality correctly with each other. That's not an issue, as it just means we'll redo the transform once more than necessary. Changelog: [Android][Fixed] Optimize BaseViewManager#setTransform to ignore duplicate values Reviewed By: NickGerleman Differential Revision: D62213726 fbshipit-source-id: 5df026030c66e31eb6a5fe6353de3706b5b7b799 --- .../react/uimanager/BaseViewManager.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index 382055fbc79..d9a79ccf2b1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -38,6 +38,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Base class that should be suitable for the majority of subclasses of {@link ViewManager}. It @@ -216,15 +217,22 @@ public abstract class BaseViewManager