question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drop in performance with a lot of objects

See original GitHub issue

Description

Hello dear developers. I just encountered big drop in performance compared with reanimated v1 when you have about 50 Views with own SharedValue and own rotate transformation (especially on android device) . V2 shows about 40 fps, when v1 shows 60. Is v1 more performant? Or I do something wrong?

Screenshots

v2

https://user-images.githubusercontent.com/39302602/104703629-9da3d400-5728-11eb-960f-7f667257cd3f.mp4

v1

https://user-images.githubusercontent.com/39302602/104703724-bdd39300-5728-11eb-9add-1c588a51279c.mp4

Steps To Reproduce

Use code below or:

  1. Add 50 Animated.Views with own Shared value and run rotate transformation

Expected behavior

60fps

Actual behavior

40fps

Snack or minimal code example

import { loop } from "react-native-redash/src/v1";

const dummy = new Array(50).fill(1);
function App() {
  return (
    <View style={{ flex: 1, flexDirection: "row", flexWrap: "wrap" }}>
      {dummy.map((_, i) => {
        const val = useSharedValue(0);

        val.value = withRepeat(
          withTiming(1, { duration: Math.random() * 2000 + 4000 }),
          -1
        );

        const style = useAnimatedStyle(() => {
          return {
            transform: [
              { rotate: interpolate(val.value, [0, 1], [0, Math.PI * 2]) + "rad" },
            ],
          };
        });

        //reanimated1 code
        // const val = loop({ duration: Math.random() * 2000 + 4000 });

        // const style = {
        //   transform: [
        //     {
        //       rotate: concat(
        //         interpolateNode(val, {
        //           inputRange: [0, 1],
        //           outputRange: [0, Math.PI * 2],
        //         }),
        //         "rad"
        //       ),
        //     },
        //   ],
        // };
        return (
          <Animated.View
            key={i}
            style={[
              {
                width: 60,
                height: 60,
                borderWidth: 1,
                backgroundColor: `hsl(${(360 / dummy.length) * i}, 100%, 40%)`,
              },
              style,
            ]}
          />
        );
      })}
    </View>
  );
}

Package versions

  • React: 16.13.1
  • React Native: 0.63.4
  • React Native Reanimated: 2.0.0-alpha.9.2
  • NodeJS: 14.15.1
  • Android 9 (Redmi Note7) but the same on IOS with bigger Views count

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
piaskowykcommented, Sep 30, 2021

We improved performance since 2.3.+ version - https://github.com/software-mansion/react-native-reanimated/pull/1879

1reaction
chybisovcommented, Jan 22, 2021

I also facing this issue, but with just 6 views, transform scale and backgroundColor. Android Samsung Galaxy S8 FPS ~40-50 😞 I use 2.0.0- rc0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Significant editorloop performance drop when only certain ...
Significant editorloop performance drop when only certain objects are selected in the inspector.
Read more >
Are there performance issues from using large numbers of ...
Yes, creating objects is more expensive compared to creating primitives. It also occupies more heap space (memory.)
Read more >
Unity Optimization : reducing 3D objects' draw calls - YouTube
This video shows how to improve the 3D game performance in Unity.In this example, I will show you how to reduce draw calls...
Read more >
java - Should you minimize the creation of a lot of small objects?
In general, no, you shouldn't avoid creating objects for fear of performance loss. There are several reasons for this.
Read more >
Improve Application Performance with These Advanced GC ...
The basic concept of generational GC is based on the idea that the longer a reference exists to an object in the heap,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found