-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Native perf benchmarking infra for Fabric components #15772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iamAbhi-916
wants to merge
22
commits into
microsoft:main
Choose a base branch
from
iamAbhi-916:native-perf-benchmarking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2632895
add native perf benchmarking infrastructure for Fabric components
iamAbhi-916 c17c4fb
Added all 6 missing components
iamAbhi-916 f1ab9f9
Merge branch 'microsoft:main' into native-perf-benchmarking
iamAbhi-916 1ea1ee1
Change files
iamAbhi-916 262ec6e
Merge branch 'native-perf-benchmarking' of https://github.com/iamAbhi…
iamAbhi-916 a961a86
updates baselines in release mode
iamAbhi-916 72a7a8e
add winAppsdk and dev mode
iamAbhi-916 f220f42
Change files
iamAbhi-916 8deaec1
use winget as installer
iamAbhi-916 f0c8c3a
use direct download from download.microsoft.com
iamAbhi-916 ba8609d
relax TouchableOpacity bulk threshold in JS test
iamAbhi-916 b56fb00
Merge branch 'main' into native-perf-benchmarking
iamAbhi-916 3ee4400
Merge branch 'main' into native-perf-benchmarking
iamAbhi-916 db41d8a
update snapshots
iamAbhi-916 90d0aed
Merge branch 'main' into native-perf-benchmarking
iamAbhi-916 49873af
update snapshots
iamAbhi-916 c3ffcc7
review comments and segregate native tests
iamAbhi-916 1074d2f
poll for valid perf JSON instead of single read to handle transient U…
iamAbhi-916 ff3e37f
nit
iamAbhi-916 0f94c2b
lint:fix and format
iamAbhi-916 4f8d280
Merge branch 'main' into native-perf-benchmarking
iamAbhi-916 2b531bf
fix: use --msbuildprops instead of -- /p: for SDK version override
iamAbhi-916 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
change/@react-native-windows-automation-a4bcc22f-ba9f-409b-baeb-eac0e646b9d6.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "add native perf benchmarking infrastructure for Fabric components", | ||
| "packageName": "@react-native-windows/automation", | ||
| "email": "74712637+iamAbhi-916@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@react-native-windows-perf-testing-4734971c-72bb-4389-b990-27e212a15295.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "add native perf benchmarking infrastructure for Fabric components", | ||
| "packageName": "@react-native-windows/perf-testing", | ||
| "email": "74712637+iamAbhi-916@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
265 changes: 265 additions & 0 deletions
265
...tive-windows/tester/src/js/examples-win/NativePerfBenchmark/NativePerfBenchmarkExample.js
This file contains hidden or 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,265 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| * @format | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const React = require('react'); | ||
| const { | ||
| View, | ||
| Text, | ||
| TextInput, | ||
| Image, | ||
| ScrollView, | ||
| FlatList, | ||
| SectionList, | ||
| Switch, | ||
| ActivityIndicator, | ||
| Button, | ||
| Modal, | ||
| Pressable, | ||
| TouchableHighlight, | ||
| TouchableOpacity, | ||
| StyleSheet, | ||
| } = require('react-native'); | ||
|
|
||
| const {useState, useRef, useCallback, useEffect} = React; | ||
|
|
||
| const PHASE_IDLE = 'idle'; | ||
| const PHASE_CLEARING = 'clearing'; | ||
| const PHASE_MOUNTING = 'mounting'; | ||
| const PHASE_DONE = 'done'; | ||
|
|
||
| const COMPONENT_REGISTRY = { | ||
| View: () => <View style={styles.target} />, | ||
| Text: () => <Text style={styles.target}>Benchmark Text</Text>, | ||
| TextInput: () => ( | ||
| <TextInput style={styles.targetInput} placeholder="Benchmark" /> | ||
| ), | ||
| Image: () => ( | ||
| <Image | ||
| style={styles.targetImage} | ||
| source={require('../../assets/uie_thumb_normal.png')} | ||
| /> | ||
| ), | ||
| ScrollView: () => ( | ||
| <ScrollView style={styles.target}> | ||
| {Array.from({length: 20}, (_, i) => ( | ||
| <View key={i} style={styles.scrollItem} /> | ||
| ))} | ||
| </ScrollView> | ||
| ), | ||
| FlatList: () => ( | ||
| <FlatList | ||
| style={styles.target} | ||
| data={Array.from({length: 50}, (_, i) => ({key: String(i)}))} | ||
| renderItem={({item}) => <Text>{item.key}</Text>} | ||
| /> | ||
| ), | ||
| SectionList: () => ( | ||
| <SectionList | ||
| style={styles.target} | ||
| sections={[ | ||
| {title: 'A', data: ['A1', 'A2', 'A3']}, | ||
| {title: 'B', data: ['B1', 'B2', 'B3']}, | ||
| ]} | ||
| renderItem={({item}) => <Text>{item}</Text>} | ||
| renderSectionHeader={({section}) => <Text>{section.title}</Text>} | ||
| /> | ||
| ), | ||
| Switch: () => <Switch value={false} />, | ||
| ActivityIndicator: () => <ActivityIndicator size="large" />, | ||
| Button: () => <Button title="Benchmark" onPress={() => {}} />, | ||
| Modal: () => ( | ||
| <Modal visible={false} transparent> | ||
| <View style={styles.target} /> | ||
| </Modal> | ||
| ), | ||
| Pressable: () => ( | ||
| <Pressable style={styles.target}> | ||
| <Text>Press</Text> | ||
| </Pressable> | ||
| ), | ||
| TouchableHighlight: () => ( | ||
| <TouchableHighlight style={styles.target} onPress={() => {}}> | ||
| <Text>Highlight</Text> | ||
| </TouchableHighlight> | ||
| ), | ||
| TouchableOpacity: () => ( | ||
| <TouchableOpacity style={styles.target} onPress={() => {}}> | ||
| <Text>Opacity</Text> | ||
| </TouchableOpacity> | ||
| ), | ||
| }; | ||
|
|
||
| function BenchmarkRunner() { | ||
| const [componentName, setComponentName] = useState('View'); | ||
| const [runsInput, setRunsInput] = useState('15'); | ||
| const [phase, setPhase] = useState(PHASE_IDLE); | ||
| const [showTarget, setShowTarget] = useState(false); | ||
| const [resultsJson, setResultsJson] = useState(''); | ||
|
|
||
| const durationsRef = useRef([]); | ||
| const runIndexRef = useRef(0); | ||
| const totalRunsRef = useRef(15); | ||
| const markNameRef = useRef(''); | ||
|
|
||
| const finishRun = useCallback(() => { | ||
| const markEnd = `perf-end-${runIndexRef.current}`; | ||
| performance.mark(markEnd); | ||
| try { | ||
| const measure = performance.measure( | ||
| `perf-run-${runIndexRef.current}`, | ||
| markNameRef.current, | ||
| markEnd, | ||
| ); | ||
| durationsRef.current.push(measure.duration); | ||
| } catch (_) {} | ||
| performance.clearMarks(markNameRef.current); | ||
| performance.clearMarks(markEnd); | ||
| performance.clearMeasures(`perf-run-${runIndexRef.current}`); | ||
|
|
||
| runIndexRef.current++; | ||
| if (runIndexRef.current < totalRunsRef.current) { | ||
| setPhase(PHASE_CLEARING); | ||
| } else { | ||
| setShowTarget(false); | ||
| setResultsJson( | ||
| JSON.stringify({ | ||
| componentName, | ||
| runs: durationsRef.current.length, | ||
| durations: durationsRef.current, | ||
| }), | ||
| ); | ||
| setPhase(PHASE_DONE); | ||
| } | ||
| }, [componentName]); | ||
|
|
||
| useEffect(() => { | ||
| if (phase === PHASE_CLEARING) { | ||
| setShowTarget(false); | ||
| requestAnimationFrame(() => { | ||
| setPhase(PHASE_MOUNTING); | ||
| }); | ||
| } | ||
| }, [phase]); | ||
|
|
||
| useEffect(() => { | ||
| if (phase === PHASE_MOUNTING) { | ||
| const markStart = `perf-start-${runIndexRef.current}`; | ||
| markNameRef.current = markStart; | ||
| performance.mark(markStart); | ||
| setShowTarget(true); | ||
| } | ||
| }, [phase]); | ||
|
|
||
| useEffect(() => { | ||
| if (phase === PHASE_MOUNTING && showTarget) { | ||
| requestAnimationFrame(() => { | ||
| finishRun(); | ||
| }); | ||
| } | ||
| }, [phase, showTarget, finishRun]); | ||
|
|
||
| const handleRun = useCallback(() => { | ||
| const runs = parseInt(runsInput, 10) || 15; | ||
| totalRunsRef.current = runs; | ||
| runIndexRef.current = 0; | ||
| durationsRef.current = []; | ||
| setResultsJson(''); | ||
| setPhase(PHASE_CLEARING); | ||
| }, [runsInput]); | ||
|
|
||
| const ComponentFactory = COMPONENT_REGISTRY[componentName]; | ||
|
|
||
| return ( | ||
| <View style={styles.container}> | ||
| <View style={styles.controls}> | ||
| <TextInput | ||
| testID="perf-component-input" | ||
| style={styles.input} | ||
| value={componentName} | ||
| onChangeText={setComponentName} | ||
| placeholder="Component name" | ||
| /> | ||
| <TextInput | ||
| testID="perf-runs-input" | ||
| style={styles.input} | ||
| value={runsInput} | ||
| onChangeText={setRunsInput} | ||
| keyboardType="numeric" | ||
| placeholder="Runs" | ||
| /> | ||
| <Pressable | ||
| testID="perf-run-btn" | ||
| style={styles.button} | ||
| onPress={handleRun} | ||
| disabled={phase !== PHASE_IDLE && phase !== PHASE_DONE}> | ||
| <Text style={styles.buttonText}>Run Benchmark</Text> | ||
| </Pressable> | ||
| </View> | ||
|
|
||
| <Text testID="perf-status" style={styles.status}> | ||
| {phase} | ||
| </Text> | ||
|
|
||
| <View style={styles.targetContainer}> | ||
| {showTarget && ComponentFactory ? <ComponentFactory /> : null} | ||
| </View> | ||
|
|
||
| <Text testID="perf-results" style={styles.results}> | ||
| {resultsJson} | ||
| </Text> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: {flex: 1, padding: 8}, | ||
| controls: {flexDirection: 'row', gap: 8, marginBottom: 8}, | ||
| input: { | ||
| borderWidth: 1, | ||
| borderColor: '#ccc', | ||
| padding: 6, | ||
| minWidth: 100, | ||
| fontSize: 14, | ||
| }, | ||
| button: { | ||
| backgroundColor: '#0078D4', | ||
| paddingHorizontal: 16, | ||
| paddingVertical: 8, | ||
| borderRadius: 4, | ||
| justifyContent: 'center', | ||
| }, | ||
| buttonText: {color: 'white', fontWeight: 'bold'}, | ||
| status: {fontSize: 12, color: '#666', marginBottom: 4}, | ||
| targetContainer: { | ||
| minHeight: 100, | ||
| borderWidth: 1, | ||
| borderColor: '#eee', | ||
| marginBottom: 8, | ||
| }, | ||
| target: {width: 80, height: 80, backgroundColor: '#f0f0f0'}, | ||
| targetInput: {width: 200, height: 40, borderWidth: 1, borderColor: '#999'}, | ||
| targetImage: {width: 80, height: 80}, | ||
| scrollItem: {height: 20, backgroundColor: '#ddd', marginBottom: 2}, | ||
| results: {fontSize: 10, fontFamily: 'monospace', color: '#333'}, | ||
| }); | ||
|
|
||
| exports.displayName = 'NativePerfBenchmarkExample'; | ||
| exports.framework = 'React'; | ||
| exports.category = 'Basic'; | ||
| exports.title = 'Native Perf Benchmark'; | ||
| exports.description = | ||
| 'Measures native rendering pipeline via performance.mark/measure.'; | ||
|
|
||
| exports.examples = [ | ||
| { | ||
| title: 'Benchmark Runner', | ||
| render: function () { | ||
| return <BenchmarkRunner />; | ||
| }, | ||
| }, | ||
| ]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.