diff --git a/.github/workflows/perf-tests.yml b/.github/workflows/perf-tests.yml index d29a71a3290..e856145e7a2 100644 --- a/.github/workflows/perf-tests.yml +++ b/.github/workflows/perf-tests.yml @@ -66,6 +66,8 @@ jobs: - name: Compare against baselines id: compare working-directory: packages/e2e-test-app-fabric + env: + CI: 'true' run: yarn perf:ci:compare continue-on-error: true diff --git a/change/@react-native-windows-perf-testing-e9d62521-41b5-4afe-b3fa-fb4692af8369.json b/change/@react-native-windows-perf-testing-e9d62521-41b5-4afe-b3fa-fb4692af8369.json new file mode 100644 index 00000000000..f4c5c57e0ca --- /dev/null +++ b/change/@react-native-windows-perf-testing-e9d62521-41b5-4afe-b3fa-fb4692af8369.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "fix: reporter writes current measured values via temp files instead of baselines", + "packageName": "@react-native-windows/perf-testing", + "email": "74712637+iamAbhi-916@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/@react-native-windows/perf-testing/src/ci/PerfJsonReporter.ts b/packages/@react-native-windows/perf-testing/src/ci/PerfJsonReporter.ts index 9acb9250828..446832818c2 100644 --- a/packages/@react-native-windows/perf-testing/src/ci/PerfJsonReporter.ts +++ b/packages/@react-native-windows/perf-testing/src/ci/PerfJsonReporter.ts @@ -78,11 +78,11 @@ export class PerfJsonReporter { const suites: SuiteResult[] = []; for (const suite of results.testResults) { - // Load the snapshot file for this test suite (written by toMatchPerfSnapshot) - const {file: snapshotFilePath} = SnapshotManager.getSnapshotPath( + // Load the CURRENT measured values written by toMatchPerfSnapshot + // to a temp file (not the baselines — those are for comparison only) + const snapshots = SnapshotManager.loadCurrentRun( suite.testFilePath, ); - const snapshots = SnapshotManager.load(snapshotFilePath); const passed = suite.testResults.filter( t => t.status === 'passed', @@ -136,6 +136,11 @@ export class PerfJsonReporter { ); console.log(`\nšŸ“Š Perf results written to: ${this.outputFile}`); + + // Clean up temp files written by test workers + for (const suite of results.testResults) { + SnapshotManager.cleanCurrentRun(suite.testFilePath); + } } } diff --git a/packages/@react-native-windows/perf-testing/src/matchers/snapshotManager.ts b/packages/@react-native-windows/perf-testing/src/matchers/snapshotManager.ts index 3f9a3aa5d87..81daea5e241 100644 --- a/packages/@react-native-windows/perf-testing/src/matchers/snapshotManager.ts +++ b/packages/@react-native-windows/perf-testing/src/matchers/snapshotManager.ts @@ -72,4 +72,50 @@ export class SnapshotManager { static buildKey(testName: string): string { return `${testName} 1`; } + + /** + * Path to the temp file where the current run's measured values are stored. + * Written by toMatchPerfSnapshot (worker), read by PerfJsonReporter (main). + */ + static getCurrentRunPath(testFilePath: string): string { + const testDir = path.dirname(testFilePath); + const snapshotDir = path.join(testDir, '__perf_snapshots__'); + return path.join( + snapshotDir, + `${path.basename(testFilePath)}.perf-current.json`, + ); + } + + /** + * Record a single test's measured values to the current-run temp file. + * Called from the test worker process by toMatchPerfSnapshot. + */ + static recordCurrentRun( + testFilePath: string, + key: string, + entry: SnapshotEntry, + ): void { + const currentPath = this.getCurrentRunPath(testFilePath); + const existing = this.load(currentPath); + existing[key] = entry; + this.save(currentPath, existing); + } + + /** + * Load the current run's measured values from the temp file. + * Called from the main process by PerfJsonReporter. + */ + static loadCurrentRun(testFilePath: string): SnapshotFile { + return this.load(this.getCurrentRunPath(testFilePath)); + } + + /** + * Remove the current-run temp file (cleanup after reporting). + */ + static cleanCurrentRun(testFilePath: string): void { + const p = this.getCurrentRunPath(testFilePath); + if (fs.existsSync(p)) { + fs.unlinkSync(p); + } + } } diff --git a/packages/@react-native-windows/perf-testing/src/matchers/toMatchPerfSnapshot.ts b/packages/@react-native-windows/perf-testing/src/matchers/toMatchPerfSnapshot.ts index 12911e959cb..929e1462472 100644 --- a/packages/@react-native-windows/perf-testing/src/matchers/toMatchPerfSnapshot.ts +++ b/packages/@react-native-windows/perf-testing/src/matchers/toMatchPerfSnapshot.ts @@ -192,6 +192,13 @@ expect.extend({ }; } + // Record current measured values for the CI reporter + SnapshotManager.recordCurrentRun(testPath, snapshotKey, { + metrics: received, + threshold, + capturedAt: new Date().toISOString(), + }); + // COMPARE MODE const {errors, warnings} = compareAgainstBaseline( received, diff --git a/packages/e2e-test-app-fabric/test/__perf__/core/View.perf-test.tsx b/packages/e2e-test-app-fabric/test/__perf__/core/View.perf-test.tsx index 9597ed2fa42..ee4d4429881 100644 --- a/packages/e2e-test-app-fabric/test/__perf__/core/View.perf-test.tsx +++ b/packages/e2e-test-app-fabric/test/__perf__/core/View.perf-test.tsx @@ -58,7 +58,9 @@ class ViewPerfTest extends ComponentPerfTestBase { const NestedViews = () => ( {Array.from({length: count}, (_, i) => ( - + + + ))} );