Skip to content

Commit 68dfed4

Browse files
hoxyqmeta-codesync[bot]
authored andcommitted
JSX Fantom benchmark (#54336)
Summary: Pull Request resolved: #54336 # Changelog: [Internal] Adds a benchmark that is scoped to JSX scenario. React uses createTask() on JSX instances to preserve owner stacks relationship, and so users can see tree-like stacks in the debugger. Since this only happens in DEV, I have to force dev mode in Fantom as well. Differential Revision: D85860981
1 parent 0781648 commit 68dfed4

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
* @fantom_mode dev
10+
*/
11+
12+
/**
13+
* We force the DEV mode, because React only uses console.createTask in DEV builds.
14+
*/
15+
16+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
17+
18+
import * as Fantom from '@react-native/fantom';
19+
import {View} from 'react-native';
20+
21+
let root;
22+
23+
function Node(props: {depth: number}): React.Node {
24+
if (props.depth === 500) {
25+
return <View />;
26+
}
27+
28+
return (
29+
<View>
30+
<Node depth={props.depth + 1} />
31+
</View>
32+
);
33+
}
34+
function Root(props: {prop: boolean}): React.Node {
35+
return <Node depth={0} />;
36+
}
37+
38+
Fantom.unstable_benchmark
39+
.suite(
40+
`console.createTask ${typeof console.createTask === 'function' ? 'installed' : 'removed'}`,
41+
{
42+
minIterations: 100,
43+
disableOptimizedBuildCheck: true,
44+
},
45+
)
46+
.test(
47+
'Rendering 1000 views',
48+
() => {
49+
let recursiveViews: React.MixedElement;
50+
for (let i = 0; i < 1000; ++i) {
51+
recursiveViews = <View>{recursiveViews}</View>;
52+
}
53+
54+
Fantom.runTask(() => root.render(recursiveViews));
55+
},
56+
{
57+
beforeEach: () => {
58+
root = Fantom.createRoot();
59+
},
60+
afterEach: () => {
61+
root.destroy();
62+
},
63+
},
64+
)
65+
.test(
66+
'Updating a subtree of 500 nodes',
67+
() => {
68+
Fantom.runTask(() => root.render(<Root prop={false} />));
69+
},
70+
{
71+
beforeEach: () => {
72+
root = Fantom.createRoot();
73+
Fantom.runTask(() => root.render(<Root prop={true} />));
74+
},
75+
afterEach: () => {
76+
root.destroy();
77+
},
78+
},
79+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
* @fantom_mode dev
10+
*/
11+
12+
/**
13+
* We force the DEV mode, because React only uses console.createTask in DEV builds.
14+
*/
15+
16+
//$FlowExpectedError[cannot-write]
17+
delete console.createTask;
18+
19+
require('./consoleCreateTask-jsx-benchmark-itest.js');

0 commit comments

Comments
 (0)