ci(bench): build dist/ before pre-publish benchmark gate#1057
Conversation
Pre-publish benchmark ran against `src/` via `--strip-types`, while every historical baseline (v3.9.6 and earlier) was measured against compiled JS in `dist/` via the post-publish `--npm` path. Same code, two load paths — the load-path delta showed up as version-to-version regressions in the query/build benchmarks even though the code under test was unchanged. Adds `--dist` to `bench-config.ts` so local mode can load from `dist/`, and runs `npm run build` in the pre-publish-benchmark job before each benchmark invocation. Local developers default to `src/` unchanged. Fixes #1055 Refs #1054
|
Claude finished @carlos-alm's task —— View job PR Review Complete ✅Reviewing PR #1057: ci(bench): build dist/ before pre-publish benchmark gate Todo List:
Root Cause AnalysisProblem Being Solved: Pre-publish benchmark gate measured against Why This Approach: The fix aligns measurement methodology by building Risk Assessment: Low risk - purely additive flag with error handling for missing Configuration Change Review
|
Greptile SummaryThis PR fixes a benchmark methodology mismatch in the pre-publish gate: historical baselines were measured against compiled Confidence Score: 5/5Safe to merge — no logic bugs, no security issues; changes are confined to CI workflow and the benchmark config helper. Both changed files are straightforward: the workflow change inserts a build step in the right place and appends No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant CI as publish.yml (CI)
participant Build as npm run build
participant BenchScript as scripts/benchmark.ts (--strip-types)
participant BenchConfig as bench-config.ts
participant Dist as dist/ (compiled JS)
CI->>Build: npm run build
Build-->>CI: dist/ ready
CI->>BenchScript: node --strip-types ... --dist
BenchScript->>BenchConfig: resolveBenchmarkSource()
BenchConfig->>Dist: fs.existsSync(distDir) ✓
Dist-->>BenchConfig: srcDir = dist/
BenchConfig-->>BenchScript: { srcDir: dist/, version, cleanup }
BenchScript->>Dist: dynamic import via srcImport()
Dist-->>BenchScript: codegraph modules (compiled JS)
BenchScript-->>CI: benchmark-result.json
Reviews (3): Last reviewed commit: "Merge branch 'fix/issue-1055-bench-metho..." | Re-trigger Greptile |
| if (!npm) { | ||
| // Local mode — use repo src/, version derived from git state | ||
| // Local mode — use repo src/ (or dist/ when --dist), version from git state | ||
| const root = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1')), '..', '..'); | ||
| const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); |
There was a problem hiding this comment.
When
--npm and --dist are both supplied, dist is parsed but silently dropped in resolveBenchmarkSource() because the if (!npm) branch is never entered. A developer running node … --npm --dist would get no feedback that --dist was ignored, and the flag combination doesn't make semantic sense (npm mode always auto-selects dist/ from the installed package anyway). A small warning would prevent confusion.
| if (!npm) { | |
| // Local mode — use repo src/, version derived from git state | |
| // Local mode — use repo src/ (or dist/ when --dist), version from git state | |
| const root = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1')), '..', '..'); | |
| const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); | |
| if (dist && npm) { | |
| console.error('Warning: --dist is ignored in --npm mode (the installed package already uses dist/ automatically).'); | |
| } | |
| if (!npm) { | |
| // Local mode — use repo src/ (or dist/ when --dist), version from git state | |
| const root = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1')), '..', '..'); | |
| const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); |
There was a problem hiding this comment.
Fixed in cfea14c — added a warning when --dist is combined with --npm, since --dist is silently ignored in npm mode.
Codegraph Impact Analysis2 functions changed → 28 callers affected across 9 files
|
In --npm mode, --dist was silently ignored because the installed package already auto-selects dist/ from its prebuilt files. Print a clear warning when both flags are passed so developers don't silently get unexpected behavior.
…/optave/codegraph into fix/issue-1055-bench-methodology
Summary
src/via--strip-typeswhile every historical baseline was measured against compileddist/via the post-publish--npmpath. Same code, two load paths — version-to-version deltas were largely measurement artifacts.--disttobench-config.tsso local mode can opt intodist/. CI nownpm run builds and passes--distto all four benchmark scripts. Local developer flow (no--dist) is unchanged.Why this addresses #1055
The reported +52% on
fnDeps(and the related +2080ms native rebuild flat overhead in #1054) appeared on Linux CI between v3.9.6 and v3.10.0 even though thefnDepsquery path code (domain/queries.ts→analysis/dependencies.ts→db/repository/native-repository.ts→db/connection.ts→infrastructure/native.ts) was unchanged across those tags.What did change is how the benchmark loads the code under test:
QUERY-BENCHMARKS.mdwas produced by the post-publish workflow installing@optave/codegraph@3.9.6and running benchmarks againstdist/(bench-config.tsline 204 prefersdist/when present in npm mode).node --strip-types --import ./scripts/ts-resolve-loader.js scripts/benchmark.tsagainstsrc/. Same Rust binary, but the JS layer is now type-stripped TypeScript instead oftsc-compiled JavaScript.This PR aligns the gate with the historical methodology so 3.10.x and later are measured the same way 3.9.6 was.
Test plan
npm run buildproduces a workingdist/.node --import ./scripts/ts-resolve-loader.js scripts/query-benchmark.ts --distruns end-to-end on Mac M1 and produces sensible numbers (fnDeps depth3 = 23.2ms, in line withsrc/-loaded run at24.9ms).npx tsc --noEmitclean.Fixes #1055
Refs #1054