-
Notifications
You must be signed in to change notification settings - Fork 10
fix(scripts): trend annotations fall back to nearest non-null prior release #1120
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
carlos-alm
wants to merge
3
commits into
main
Choose a base branch
from
fix/incremental-report-trend-fallback
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.
+214
−42
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
407728f
fix(scripts): fall back to nearest non-null prior release for trend a…
carlos-alm 628d37d
fix(scripts): guard trend against zero baseline; hoist resolve trend …
carlos-alm e86c257
Merge branch 'main' into fix/incremental-report-trend-fallback
carlos-alm 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { execFileSync } from 'node:child_process'; | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const repoRoot = path.resolve(__dirname, '..', '..'); | ||
| const scriptPath = path.join(repoRoot, 'scripts', 'update-incremental-report.ts'); | ||
|
|
||
| // --experimental-strip-types works in Node 22.6+ through current 24.x; the | ||
| // renamed --strip-types was added then removed again across 24.x minor | ||
| // versions, so prefer the experimental name for compatibility. | ||
| const stripFlag = '--experimental-strip-types'; | ||
|
|
||
| let tmpDir: string; | ||
| let reportPath: string; | ||
| let entryPath: string; | ||
|
|
||
| beforeEach(() => { | ||
| tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-trend-fallback-')); | ||
| reportPath = path.join(tmpDir, 'INCREMENTAL-BENCHMARKS.md'); | ||
| entryPath = path.join(tmpDir, 'entry.json'); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function runScript() { | ||
| execFileSync('node', [stripFlag, scriptPath, entryPath], { | ||
| env: { ...process.env, CODEGRAPH_INCREMENTAL_REPORT_PATH: reportPath }, | ||
| stdio: 'pipe', | ||
| }); | ||
| } | ||
|
|
||
| function row(content: string, version: string, engine: string): string { | ||
| const re = new RegExp(`^\\| ${version.replace(/\./g, '\\.')} \\| ${engine} \\|.*$`, 'm'); | ||
| const m = content.match(re); | ||
| if (!m) throw new Error(`row not found for ${version}/${engine}`); | ||
| return m[0]; | ||
| } | ||
|
|
||
| describe('update-incremental-report trend fallback', () => { | ||
| it('falls back to nearest non-null prior release when previous metrics are null', () => { | ||
| // Seed: 9.9.4 has full data. 9.9.5 is the null release (workers crashed). | ||
| const initial = `# Codegraph Incremental Build Benchmarks | ||
|
|
||
| <!-- INCREMENTAL_BENCHMARK_DATA | ||
| [ | ||
| { | ||
| "version": "9.9.5", | ||
| "date": "2026-05-01", | ||
| "files": 100, | ||
| "wasm": null, | ||
| "native": null, | ||
| "resolve": { "imports": 100, "nativeBatchMs": 5, "jsFallbackMs": 10, "perImportNativeMs": 0, "perImportJsMs": 0 } | ||
| }, | ||
| { | ||
| "version": "9.9.4", | ||
| "date": "2026-04-18", | ||
| "files": 100, | ||
| "wasm": { "fullBuildMs": 1000, "noopRebuildMs": 10, "oneFileRebuildMs": 50 }, | ||
| "native": { "fullBuildMs": 500, "noopRebuildMs": 5, "oneFileRebuildMs": 25 }, | ||
| "resolve": { "imports": 100, "nativeBatchMs": 5, "jsFallbackMs": 10, "perImportNativeMs": 0, "perImportJsMs": 0 } | ||
| } | ||
| ] | ||
| --> | ||
| `; | ||
| fs.writeFileSync(reportPath, initial); | ||
| // New release 9.9.6 doubles wasm full-build and 13x's no-op rebuild — should | ||
| // compare against 9.9.4 (skipping null 9.9.5) and show large regressions. | ||
| fs.writeFileSync( | ||
| entryPath, | ||
| JSON.stringify({ | ||
| version: '9.9.6', | ||
| date: '2026-04-30', | ||
| files: 100, | ||
| wasm: { fullBuildMs: 2000, noopRebuildMs: 130, oneFileRebuildMs: 60 }, | ||
| native: { fullBuildMs: 600, noopRebuildMs: 8, oneFileRebuildMs: 30 }, | ||
| resolve: { | ||
| imports: 100, | ||
| nativeBatchMs: 5, | ||
| jsFallbackMs: 10, | ||
| perImportNativeMs: 0, | ||
| perImportJsMs: 0, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| runScript(); | ||
| const out = fs.readFileSync(reportPath, 'utf8'); | ||
|
|
||
| const wasmRow = row(out, '9.9.6', 'wasm'); | ||
| // Full build: 1000 → 2000 = +100% | ||
| expect(wasmRow).toContain('↑100%'); | ||
| // No-op: 10 → 130 = +1200% | ||
| expect(wasmRow).toContain('↑1200%'); | ||
| // 1-file: 50 → 60 = +20% | ||
| expect(wasmRow).toContain('↑20%'); | ||
|
|
||
| // And the null 9.9.5 row still renders without a trend (no prior data | ||
| // for it to compare against — it itself has no metrics). | ||
| expect(out).not.toMatch(/^\| 9\.9\.5 \| wasm \|/m); | ||
| expect(out).not.toMatch(/^\| 9\.9\.5 \| native \|/m); | ||
| }); | ||
|
|
||
| it('leaves trend empty when no prior release has the metric at all', () => { | ||
| const initial = `# Codegraph Incremental Build Benchmarks | ||
|
|
||
| <!-- INCREMENTAL_BENCHMARK_DATA | ||
| [] | ||
| --> | ||
| `; | ||
| fs.writeFileSync(reportPath, initial); | ||
| fs.writeFileSync( | ||
| entryPath, | ||
| JSON.stringify({ | ||
| version: '1.0.0', | ||
| date: '2026-01-01', | ||
| files: 50, | ||
| wasm: { fullBuildMs: 1000, noopRebuildMs: 10, oneFileRebuildMs: 50 }, | ||
| native: { fullBuildMs: 500, noopRebuildMs: 5, oneFileRebuildMs: 25 }, | ||
| resolve: { | ||
| imports: 50, | ||
| nativeBatchMs: 1, | ||
| jsFallbackMs: 2, | ||
| perImportNativeMs: 0, | ||
| perImportJsMs: 0, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| runScript(); | ||
| const out = fs.readFileSync(reportPath, 'utf8'); | ||
| const wasmRow = row(out, '1.0.0', 'wasm'); | ||
| // No prior history => no arrow annotations on any cell | ||
| expect(wasmRow).not.toContain('↑'); | ||
| expect(wasmRow).not.toContain('↓'); | ||
| expect(wasmRow).not.toContain('~'); | ||
| }); | ||
| }); |
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.
natT/jsTresolve trends are computed insideengineRow, which is called once for each engine type per release. Sinceh.resolveis release-level (not engine-specific),findPrevMetricfornativeBatchMsandjsFallbackMsis invoked twice per release — returning identical results both times. This is harmless but wasteful for long history arrays. Consider hoisting the resolve trend calls to the call site, alongside thenativeRow/wasmRowpair, so they are computed once and passed in.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.
Fixed in 628d37d — hoisted findPrevMetric for the release-level resolve metrics (nativeBatchMs, jsFallbackMs) to the call site and pass them into engineRow, so they are computed once per release instead of twice.