forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic benchmarks for rendering views (facebook#49008)
Summary: Changelog: [internal] We're modifying some core APIs in the RN render in following diffs, so this adds a simple benchmark as a safety mechanism to verify those don't regress performance significantly. Reviewed By: yungsters Differential Revision: D68772175
- Loading branch information
1 parent
5d7feda
commit 3a299e7
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/react-native/Libraries/Components/View/__tests__/View-benchmark-itest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
* @fantom_flags enableAccessToHostTreeInFabric:true | ||
*/ | ||
|
||
import '../../../../Libraries/Core/InitializeCore.js'; | ||
|
||
import View from '../View'; | ||
import Fantom from '@react-native/fantom'; | ||
import * as React from 'react'; | ||
|
||
let root; | ||
let thousandViews: React.MixedElement; | ||
|
||
Fantom.unstable_benchmark | ||
.suite('View') | ||
.add( | ||
'render 100 uncollapsable views', | ||
() => { | ||
Fantom.runTask(() => root.render(thousandViews)); | ||
}, | ||
{ | ||
beforeAll: () => { | ||
let views: React.Node = null; | ||
for (let i = 0; i < 100; i++) { | ||
views = ( | ||
<View | ||
collapsable={false} | ||
id={String(i)} | ||
nativeID={String(i)} | ||
style={{width: i + 1, height: i + 1}}> | ||
{views} | ||
</View> | ||
); | ||
} | ||
// $FlowExpectedError[incompatible-type] | ||
thousandViews = views; | ||
}, | ||
beforeEach: () => { | ||
root = Fantom.createRoot(); | ||
}, | ||
afterEach: () => { | ||
root.destroy(); | ||
}, | ||
}, | ||
) | ||
.add( | ||
'render 1000 uncollapsable views', | ||
() => { | ||
Fantom.runTask(() => root.render(thousandViews)); | ||
}, | ||
{ | ||
beforeAll: () => { | ||
let views: React.Node = null; | ||
for (let i = 0; i < 1000; i++) { | ||
views = ( | ||
<View | ||
collapsable={false} | ||
id={String(i)} | ||
nativeID={String(i)} | ||
style={{width: i + 1, height: i + 1}}> | ||
{views} | ||
</View> | ||
); | ||
} | ||
// $FlowExpectedError[incompatible-type] | ||
thousandViews = views; | ||
}, | ||
beforeEach: () => { | ||
root = Fantom.createRoot(); | ||
}, | ||
afterEach: () => { | ||
root.destroy(); | ||
}, | ||
}, | ||
); |