-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Fabric]: Performance Tests for React Native Windows #15666
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
16
commits into
microsoft:main
Choose a base branch
from
iamAbhi-916:perf-test
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.
+8,919
−3
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
81357e6
perf testing v1( view , text , textinput)
iamAbhi-916 eefff01
Fixed spike testing by using median and other issues
iamAbhi-916 7781ee0
chore: gitignore perf-testing build output
iamAbhi-916 eb61f7c
remove scripts/ as separate folder
iamAbhi-916 280966e
add component perf tests for Button, Image, ScrollView, Switch, Modal…
iamAbhi-916 8199890
Cleanup
iamAbhi-916 08decec
Merge branch 'main' into perf-test
iamAbhi-916 dd04ee9
Change files
iamAbhi-916 a258546
Merge branch 'perf-test' of https://github.com/iamAbhi-916/react-nati…
iamAbhi-916 71d3d6c
lint fix and format
iamAbhi-916 ef53668
cleanup
iamAbhi-916 d3f6781
fix pipeline issues with cachedAct!
iamAbhi-916 823eb98
Save PR number to artifact for future report workflow
iamAbhi-916 23167f2
remove tsconfig from tracking
iamAbhi-916 e6004e8
review comments
iamAbhi-916 71604ee
update baselines
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: Perf Tests | ||
|
|
||
| # Triggers on PRs touching source that could affect perf, | ||
| # and on pushes to main/stable for baseline updates. | ||
| on: | ||
| pull_request: | ||
| branches: [main, '*-stable'] | ||
| paths: | ||
| - 'vnext/**' | ||
| - 'packages/**' | ||
| - 'vnext/Scripts/perf/**' | ||
| - '.github/workflows/perf-tests.yml' | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'packages/e2e-test-app-fabric/test/__perf__/**' | ||
|
|
||
| # Allow manual trigger for debugging | ||
| workflow_dispatch: | ||
|
|
||
| # Cancel in-progress runs for the same PR | ||
| concurrency: | ||
| group: perf-${{ github.event.pull_request.number || github.sha }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| perf-tests: | ||
| name: Component Performance Tests | ||
| runs-on: windows-latest | ||
| timeout-minutes: 30 | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: read | ||
|
|
||
| steps: | ||
| # ── Setup ────────────────────────────────────────────── | ||
| - name: Checkout head (PR) | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Need history for baseline comparison | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| cache: yarn | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn install --frozen-lockfile | ||
|
|
||
| - name: Build perf-testing package | ||
| run: yarn workspace @react-native-windows/perf-testing build | ||
|
|
||
| # ── Run Tests ────────────────────────────────────────── | ||
| - name: Run perf tests | ||
| id: perf-run | ||
| working-directory: packages/e2e-test-app-fabric | ||
| env: | ||
| CI: 'true' | ||
| RN_TARGET_PLATFORM: windows | ||
| run: yarn perf:ci | ||
| continue-on-error: true # Don't fail here — let comparison decide | ||
|
|
||
| # ── Compare & Report ─────────────────────────────────── | ||
| - name: Compare against baselines | ||
| id: compare | ||
| working-directory: packages/e2e-test-app-fabric | ||
| run: yarn perf:ci:compare | ||
| continue-on-error: true | ||
|
|
||
| - name: Save PR number | ||
| if: github.event_name == 'pull_request' | ||
| run: echo "${{ github.event.pull_request.number }}" > packages/e2e-test-app-fabric/.perf-results/pr-number.txt | ||
|
|
||
| - name: Upload perf results | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: perf-results | ||
| path: | | ||
| packages/e2e-test-app-fabric/.perf-results/ | ||
| packages/e2e-test-app-fabric/test/__perf__/**/__perf_snapshots__/ | ||
| retention-days: 30 | ||
|
|
||
| # ── Status Gate ──────────────────────────────────────── | ||
| - name: Check for regressions | ||
| if: steps.compare.outcome == 'failure' | ||
| run: | | ||
| echo "::error::Performance regressions detected. See PR comment for details." | ||
| exit 1 | ||
7 changes: 7 additions & 0 deletions
7
change/@react-native-windows-perf-testing-f0fab0f1-4984-4664-b8af-b24ff2f15cd7.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": "Performance tests for react native windows(Fabric)", | ||
| "packageName": "@react-native-windows/perf-testing", | ||
| "email": "74712637+iamAbhi-916@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/react-native-windows-1f753cb4-5264-49b2-a35d-47fd9d986207.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": "Performance tests for react native windows(Fabric)", | ||
| "packageName": "react-native-windows", | ||
| "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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| * | ||
| * @format | ||
| */ | ||
|
|
||
| module.exports = { | ||
| extends: ['@rnw-scripts/eslint-config'], | ||
| parserOptions: { | ||
| tsconfigRootDir: __dirname, | ||
| }, | ||
| }; |
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,3 @@ | ||
| lib/ | ||
| lib-commonjs/ | ||
| *.tsbuildinfo |
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,155 @@ | ||
| # @react-native-windows/perf-testing | ||
|
|
||
| Performance testing utilities for React Native Windows components. | ||
|
|
||
| ## Overview | ||
|
|
||
| This package provides infrastructure for measuring and tracking performance of React Native components. It enables: | ||
|
|
||
| - **Automated performance regression detection** on every PR | ||
| - **Component-wise performance baselines** (mount, unmount, re-render times) | ||
| - **Lightweight perf snapshots** similar to Jest snapshots | ||
| - **Easy extensibility** for new components via base classes | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @react-native-windows/perf-testing --save-dev | ||
| # or | ||
| yarn add @react-native-windows/perf-testing --dev | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### 1. Create a Performance Test | ||
|
|
||
| ```typescript | ||
| import { ComponentPerfTestBase, IScenario } from '@react-native-windows/perf-testing'; | ||
| import { View } from 'react-native'; | ||
|
|
||
| class ViewPerfTest extends ComponentPerfTestBase { | ||
| readonly componentName = 'View'; | ||
| readonly category = 'core' as const; | ||
| readonly testId = 'perf-test-view'; | ||
|
|
||
| createComponent(props?: Record<string, unknown>) { | ||
| return <View testID={this.testId} {...props} />; | ||
| } | ||
|
|
||
| getCustomScenarios(): IScenario[] { | ||
| return [ | ||
| { | ||
| name: 'nested-views', | ||
| description: 'Test nested views performance', | ||
| run: () => this.measureNestedViews(50), | ||
| }, | ||
| ]; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### 2. Write Tests | ||
|
|
||
| ```typescript | ||
| const viewPerfTest = new ViewPerfTest(); | ||
|
|
||
| describe('View Performance', () => { | ||
| test('mount time', async () => { | ||
| const perf = await viewPerfTest.measureMount(); | ||
| expect(perf).toMatchPerfSnapshot(); | ||
| }); | ||
|
|
||
| test('rerender time', async () => { | ||
| const perf = await viewPerfTest.measureRerender(); | ||
| expect(perf).toMatchPerfSnapshot(); | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| ### 3. Run Tests | ||
|
|
||
| ```bash | ||
| # Run perf tests | ||
| yarn perf | ||
|
|
||
| # Update baselines | ||
| yarn perf:update | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| ### Core Functions | ||
|
|
||
| | Function | Description | | ||
| |----------|-------------| | ||
| | `measurePerf(component, options)` | Core measurement function | | ||
| | `toMatchPerfSnapshot(threshold?)` | Jest matcher for perf snapshots | | ||
|
|
||
| ### Base Classes | ||
|
|
||
| | Class | Description | | ||
| |-------|-------------| | ||
| | `ComponentPerfTestBase` | Abstract base class for component perf tests | | ||
|
|
||
| ### Interfaces | ||
|
|
||
| | Interface | Description | | ||
| |-----------|-------------| | ||
| | `PerfMetrics` | Measurement results | | ||
| | `PerfThreshold` | Pass/fail thresholds | | ||
| | `IComponentPerfTest` | Contract for component tests | | ||
| | `IScenario` | Custom scenario interface | | ||
|
|
||
| ### Threshold Presets | ||
|
|
||
| ```typescript | ||
| import { ThresholdPresets } from '@react-native-windows/perf-testing'; | ||
|
|
||
| // Available presets | ||
| ThresholdPresets.core // 10% regression threshold | ||
| ThresholdPresets.list // 15% for list components | ||
| ThresholdPresets.interactive // 20% for animated components | ||
| ThresholdPresets.community // 25% relaxed threshold for external use | ||
| ``` | ||
|
|
||
| ## Extending for Custom Components | ||
|
|
||
| Community developers can create perf tests for their custom native components: | ||
|
|
||
| ```typescript | ||
| import { ComponentPerfTestBase } from '@react-native-windows/perf-testing'; | ||
| import { MyCustomSlider } from 'my-custom-component'; | ||
|
|
||
| class MyCustomSliderPerfTest extends ComponentPerfTestBase { | ||
| readonly componentName = 'MyCustomSlider'; | ||
| readonly category = 'custom' as const; | ||
| readonly testId = 'perf-test-slider'; | ||
|
|
||
| createComponent(props?: Record<string, unknown>) { | ||
| return <MyCustomSlider testID={this.testId} {...props} />; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Jest Setup | ||
|
|
||
| Add to your Jest setup file: | ||
|
|
||
| ```typescript | ||
| import '@react-native-windows/perf-testing/matchers'; | ||
| ``` | ||
|
|
||
| ### Custom Thresholds | ||
|
|
||
| ```typescript | ||
| expect(perf).toMatchPerfSnapshot({ | ||
| maxDurationIncrease: 15, // Allow 15% regression | ||
| maxRenderCount: 5, | ||
| }); | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| MIT |
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,9 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| * | ||
| * @format | ||
| * @ts-check | ||
| */ | ||
|
|
||
| require('@rnw-scripts/just-task'); |
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,67 @@ | ||
| { | ||
| "name": "@react-native-windows/perf-testing", | ||
| "version": "0.0.0-canary.1031", | ||
| "description": "Performance testing utilities for React Native Windows components", | ||
| "main": "lib-commonjs/index.js", | ||
| "types": "lib-commonjs/index.d.ts", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/microsoft/react-native-windows", | ||
| "directory": "packages/@react-native-windows/perf-testing" | ||
| }, | ||
| "license": "MIT", | ||
| "private": false, | ||
| "scripts": { | ||
| "build": "rnw-scripts build", | ||
| "clean": "rnw-scripts clean", | ||
| "lint": "rnw-scripts lint", | ||
| "lint:fix": "rnw-scripts lint:fix", | ||
| "watch": "rnw-scripts watch" | ||
| }, | ||
| "dependencies": { | ||
| "@react-native-windows/fs": "0.82.0-preview.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@rnw-scripts/eslint-config": "1.2.38", | ||
| "@rnw-scripts/just-task": "2.3.58", | ||
| "@rnw-scripts/ts-config": "2.0.6", | ||
| "@types/jest": "^29.2.2", | ||
| "@types/node": "^22.14.0", | ||
| "@types/react": "^19.0.0", | ||
| "@typescript-eslint/eslint-plugin": "^7.1.1", | ||
| "@typescript-eslint/parser": "^7.1.1", | ||
| "eslint": "^8.19.0", | ||
| "prettier": "2.8.8", | ||
| "typescript": "5.0.4" | ||
| }, | ||
| "peerDependencies": { | ||
| "jest": ">=29.0.3", | ||
| "react": ">=18.0.0", | ||
| "react-native": ">=0.72.0", | ||
| "react-test-renderer": ">=18.0.0" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "react-test-renderer": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "files": [ | ||
| "lib-commonjs", | ||
| "README.md" | ||
| ], | ||
| "beachball": { | ||
| "defaultNpmTag": "preview", | ||
| "disallowedChangeTypes": [ | ||
| "major", | ||
| "minor", | ||
| "patch", | ||
| "premajor", | ||
| "preminor", | ||
| "prepatch" | ||
| ] | ||
| }, | ||
| "promoteRelease": true, | ||
| "engines": { | ||
| "node": ">= 22" | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this line
continue-on-error: true hides the failure status, so checking for conclusion == 'failure' doesn't work right?
https://github.com/microsoft/react-native-windows/pull/15666/changes#diff-af705009ee2302472ab01c2ab771de538be4205f91fb78c2ccce6a8e24548995R70