Skip to content

Commit 0f3ea48

Browse files
fix: align perf history with perf-data branch layout
- Add history download step to unified pr-report.yaml reading from baselines/ on perf-data branch (the actual layout) - Fix loadHistoricalReports to handle flat JSON files, not just subdirectories with perf-metrics.json - Handle zero-baseline edge case in trendDirection: return 'rising' when firstMean=0 but secondMean>0 instead of masking as 'stable' Addresses review feedback: #9939 (review)
1 parent 9f5882b commit 0f3ea48

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

.github/workflows/pr-report.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ jobs:
173173
path: temp/perf-baseline/
174174
if_no_artifact_found: warn
175175

176+
- name: Download perf history from perf-data branch
177+
if: steps.pr-meta.outputs.skip != 'true' && steps.find-perf.outputs.status == 'ready'
178+
continue-on-error: true
179+
run: |
180+
if git ls-remote --exit-code origin perf-data >/dev/null 2>&1; then
181+
git fetch origin perf-data --depth=1
182+
mkdir -p temp/perf-history
183+
for file in $(git ls-tree --name-only origin/perf-data baselines/ 2>/dev/null | sort -r | head -10); do
184+
git show "origin/perf-data:${file}" > "temp/perf-history/$(basename "$file")" 2>/dev/null || true
185+
done
186+
echo "Loaded $(ls temp/perf-history/*.json 2>/dev/null | wc -l) historical baselines"
187+
fi
188+
176189
- name: Generate unified report
177190
if: steps.pr-meta.outputs.skip != 'true'
178191
run: >

scripts/perf-report.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ function groupByName(
7070
function loadHistoricalReports(): PerfReport[] {
7171
if (!existsSync(HISTORY_DIR)) return []
7272
const reports: PerfReport[] = []
73-
for (const dir of readdirSync(HISTORY_DIR)) {
74-
const filePath = join(HISTORY_DIR, dir, 'perf-metrics.json')
73+
for (const entry of readdirSync(HISTORY_DIR)) {
74+
const entryPath = join(HISTORY_DIR, entry)
75+
const filePath = entry.endsWith('.json')
76+
? entryPath
77+
: join(entryPath, 'perf-metrics.json')
7578
if (!existsSync(filePath)) continue
7679
try {
7780
reports.push(JSON.parse(readFileSync(filePath, 'utf-8')) as PerfReport)

scripts/perf-stats.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ describe('trendDirection', () => {
182182
it('returns stable for small fluctuations within 10%', () => {
183183
expect(trendDirection([100, 100, 100, 105, 105, 105])).toBe('stable')
184184
})
185+
186+
it('detects rising when baseline is zero but current is non-zero', () => {
187+
expect(trendDirection([0, 0, 0, 5, 5, 5])).toBe('rising')
188+
})
189+
190+
it('returns stable when both halves are zero', () => {
191+
expect(trendDirection([0, 0, 0, 0, 0, 0])).toBe('stable')
192+
})
185193
})
186194

187195
describe('trendArrow', () => {

scripts/perf-stats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function trendDirection(values: number[]): TrendDirection {
9393
const firstMean = firstHalf.reduce((a, b) => a + b, 0) / firstHalf.length
9494
const secondMean = secondHalf.reduce((a, b) => a + b, 0) / secondHalf.length
9595

96-
if (firstMean === 0) return 'stable'
96+
if (firstMean === 0) return secondMean > 0 ? 'rising' : 'stable'
9797
const changePct = ((secondMean - firstMean) / firstMean) * 100
9898

9999
if (changePct > 10) return 'rising'

0 commit comments

Comments
 (0)