Skip to content

Commit d2fa1cd

Browse files
rubennortefacebook-github-bot
authored andcommitted
Create basic benchmark for Animated (#52874)
Summary: Pull Request resolved: #52874 Changelog: [internal] This creates a basic benchmark for the Animated API, which shows that **using Animated**, even without setting up animations, **makes rendering 3x slower** (similar when setting up a JS driven animation), but **6x slower when it sets up a native animation.** Baseline: ### Animated (mode 🚀) ### | (index) | Task name | Latency average (ns) | Latency median (ns) | Throughput average (ops/s) | Throughput median (ops/s) | Samples | | ------- | ---------------------------------------------------------------------------- | --------------------- | ----------------------- | -------------------------- | ------------------------- | ------- | | 0 | 'render 1 views' | '85320.76 ± 1.27%' | '82484.00' | '11994 ± 0.09%' | '12124' | 11721 | | 1 | 'render 10 views' | '399462.22 ± 1.03%' | '387702.00' | '2552 ± 0.29%' | '2579' | 2505 | | 2 | 'render 100 views' | '3317795.78 ± 0.90%' | '3232351.00 ± 70.00' | '303 ± 0.74%' | '309' | 302 | | 3 | 'render 1 animated views (without no animations set up)' | '172534.31 ± 0.67%' | '168423.00' | '5874 ± 0.14%' | '5937' | 5796 | | 4 | 'render 10 animated views (without no animations set up)' | '1050582.87 ± 0.63%' | '1031899.00 ± 20.00' | '957 ± 0.37%' | '969' | 952 | | 5 | 'render 100 animated views (without no animations set up)' | '9255133.10 ± 1.06%' | '8990333.00' | '108 ± 0.94%' | '111' | 109 | | 6 | 'render 1 animated views (with a single animation set up - JS driven)' | '203422.03 ± 0.50%' | '198478.00' | '4966 ± 0.17%' | '5038' | 4916 | | 7 | 'render 10 animated views (with a single animation set up - JS driven)' | '1305600.39 ± 0.37%' | '1288088.00 ± 15.00' | '768 ± 0.30%' | '776' | 766 | | 8 | 'render 100 animated views (with a single animation set up - JS driven)' | '12084658.14 ± 1.51%' | '11854181.00 ± 8493.00' | '83 ± 1.27%' | '84' | 84 | | 9 | 'render 1 animated views (with a single animation set up - native driven)' | '313494.69 ± 0.32%' | '308673.00' | '3206 ± 0.19%' | '3240' | 3190 | | 10 | 'render 10 animated views (with a single animation set up - native driven)' | '2223507.22 ± 0.50%' | '2184839.00 ± 70.00' | '451 ± 0.41%' | '458' | 450 | | 11 | 'render 100 animated views (with a single animation set up - native driven)' | '21352575.02 ± 0.71%' | '21239136.00 ± 2824.00' | '47 ± 0.69%' | '47' | 64 | Reviewed By: christophpurrer Differential Revision: D79085920 fbshipit-source-id: 1dc13208da49cc325995f3455eaf86c4eb1e4d47
1 parent 797d14d commit d2fa1cd

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
12+
13+
import * as Fantom from '@react-native/fantom';
14+
import * as React from 'react';
15+
import {Animated, View, useAnimatedValue} from 'react-native';
16+
17+
function MyApp() {
18+
return (
19+
<View
20+
style={[
21+
{
22+
width: 100,
23+
height: 100,
24+
opacity: 1,
25+
},
26+
]}
27+
/>
28+
);
29+
}
30+
31+
function MyAnimatedApp() {
32+
return (
33+
<Animated.View
34+
style={[
35+
{
36+
width: 100,
37+
height: 100,
38+
opacity: 1,
39+
},
40+
]}
41+
/>
42+
);
43+
}
44+
45+
function MyAnimatedAppWithAnimation() {
46+
const opacity = useAnimatedValue(1);
47+
48+
return (
49+
<Animated.View
50+
style={[
51+
{
52+
width: 100,
53+
height: 100,
54+
opacity,
55+
},
56+
]}
57+
/>
58+
);
59+
}
60+
61+
function MyAnimatedAppWithNativeAnimation() {
62+
const opacity = useAnimatedValue(1, {useNativeDriver: true});
63+
64+
return (
65+
<Animated.View
66+
style={[
67+
{
68+
width: 100,
69+
height: 100,
70+
opacity,
71+
},
72+
]}
73+
/>
74+
);
75+
}
76+
77+
const ARGS = [1, 10, 100];
78+
79+
let root = Fantom.createRoot();
80+
let element: React.MixedElement;
81+
82+
function renderElement() {
83+
Fantom.runTask(() => root.render(element));
84+
}
85+
86+
function getOptions(
87+
numberOfComponents: number,
88+
Component: React.ComponentType<{}>,
89+
): Fantom.BenchmarkTestOptions {
90+
return {
91+
beforeAll: () => {
92+
element = (
93+
<>
94+
{Array.from({length: numberOfComponents}, (_, i) => (
95+
<Component key={i} />
96+
))}
97+
</>
98+
);
99+
},
100+
beforeEach: () => {
101+
Fantom.runTask(() => root.render(<></>));
102+
},
103+
};
104+
}
105+
106+
Fantom.unstable_benchmark
107+
.suite('Animated')
108+
.test.each(
109+
ARGS,
110+
n => `render ${n} views`,
111+
renderElement,
112+
n => getOptions(n, MyApp),
113+
)
114+
.test.each(
115+
ARGS,
116+
n => `render ${n} animated views (without animations set up)`,
117+
renderElement,
118+
n => getOptions(n, MyAnimatedApp),
119+
)
120+
.test.each(
121+
ARGS,
122+
n =>
123+
`render ${n} animated views (with a single animation set up - JS driven)`,
124+
renderElement,
125+
n => getOptions(n, MyAnimatedAppWithAnimation),
126+
)
127+
.test.each(
128+
ARGS,
129+
n =>
130+
`render ${n} animated views (with a single animation set up - native driven)`,
131+
renderElement,
132+
n => getOptions(n, MyAnimatedAppWithNativeAnimation),
133+
);

0 commit comments

Comments
 (0)