Bench check

From optave/ops-codegraph-tool · View interactive version

Bench check is an AI agent skill from the GitHub repository optave/ops-codegraph-tool. Run benchmarks against a saved baseline, detect performance regressions, and update the baseline — guards against silent slowdowns

How to use this skill

Skill file

/bench-check — Performance Regression Check

Run the project's benchmark suite, compare results against a saved baseline, flag regressions beyond a threshold, and optionally update the baseline. Prevents silent performance degradation between releases.

Arguments

Phase 0 — Pre-flight

  1. Confirm we're in the codegraph repo root
  2. Check that benchmark scripts exist:
  1. Parse $ARGUMENTS:
  1. Check for existing baseline at generated/bench-check/baseline.json

Phase 1 — Run Benchmarks

Run each benchmark script and collect results. Each script outputs JSON to stdout.

1a. Build & Query Benchmark

output=$(timeout 300 node scripts/benchmark.js 2>&1)
exit_code=$?

If exit_code is 124: record "timeout" for this suite and skip to the next suite.

Else if exit_code is non-zero: record "error: $output" for this suite and skip to the next suite.

Extract:

1b. Incremental Benchmark

output=$(timeout 300 node scripts/incremental-benchmark.js 2>&1)
exit_code=$?

If exit_code is 124: record "timeout" for this suite and skip to the next suite.

Else if exit_code is non-zero: record "error: $output" for this suite and skip to the next suite.

Extract:

1c. Query Depth Benchmark

output=$(timeout 300 node scripts/query-benchmark.js 2>&1)
exit_code=$?

If exit_code is 124: record "timeout" for this suite and skip to the next suite.

Else if exit_code is non-zero: record "error: $output" for this suite and skip to the next suite.

Extract:

1d. Embedding Benchmark (optional)

output=$(timeout 300 node scripts/embedding-benchmark.js 2>&1)
exit_code=$?

If exit_code is 124: record "timeout" for this suite and skip to the next suite.

Else if exit_code is non-zero: record "error: $output" for this suite and skip to the next suite.

Extract:

Timeout: Each benchmark gets 5 minutes max (timeout 300). Exit code 124 indicates timeout — record "timeout" for that suite and continue.

Errors: If a benchmark script fails (non-zero exit), record "error: <message>" and continue with remaining benchmarks.

Phase 2 — Normalize Results

Build a flat metrics object from all benchmark results:

{
  "timestamp": "<ISO 8601>",
  "version": "<from package.json>",
  "gitRef": "<current HEAD short SHA>",
  "metrics": {
    "build.native.ms": 1234,
    "build.wasm.ms": 2345,
    "query.fnDeps.depth3.ms": 45,
    "query.fnImpact.depth3.ms": 67,
    "query.diffImpact.ms": 89,
    "incremental.noOp.ms": 12,
    "incremental.singleFile.ms": 34,
    "incremental.importResolution.ms": 56,
    "graph.nodes": 500,
    "graph.edges": 1200,
    "embedding.time.ms": 3000,
    "embedding.recall.hit1": 0.85,
    "embedding.recall.hit5": 0.95
  }
}

Adapt the metric keys to match whatever the benchmark scripts actually output — the above are representative. The goal is a flat key→number map for easy comparison.

Phase 3 — Compare Against Baseline

Skip this phase if SAVE_ONLY=true or no baseline exists.

For each metric in the current run:

  1. Look up the same metric in the baseline
  2. Guard against division-by-zero: if baseline == 0, mark the delta as "N/A — baseline was zero" and treat the metric as informational only (not a regression or improvement)
  3. Otherwise compute: delta_pct = ((current - baseline) / baseline) * 100
  4. Classify:

Direction awareness: For latency metrics (ms), higher = worse. For recall/quality metrics, higher = better. For count metrics (nodes, edges), changes are informational only — not regressions.

Regression table

| Metric | Baseline | Current | Delta | Status |

|--------|----------|---------|-------|--------|

| build.native.ms | 1200 | 1500 | +25% | REGRESSION |

| query.fnDeps.depth3.ms | 45 | 43 | -4.4% | stable |

Phase 4 — Verdict

Pre-condition check

Before evaluating verdicts, verify that at least one benchmark produced valid numeric results.

If metrics is empty (all suites produced "error" or "timeout" records):

Based on comparison results:

No regressions found

Regressions found

First run (no baseline)

Save-baseline with existing baseline (`--save-baseline`)

Phase 5 — Save Baseline

Skip this phase if COMPARE_ONLY is set. Compare-only mode never writes or commits baselines.

Skip this phase if regressions were detected in Phase 4. The baseline is only updated on a clean run.

Skip this phase if the ABORTED pre-condition was triggered in Phase 4. The baseline must not be overwritten with empty data.

When saving (initial run, --save-baseline, or passed comparison):

Write to generated/bench-check/baseline.json:

{
  "savedAt": "<ISO 8601>",
  "version": "<package version>",
  "gitRef": "<HEAD short SHA>",
  "threshold": $THRESHOLD,
  "metrics": { ... }
}

Also append a one-line summary to generated/bench-check/history.ndjson:

{"timestamp":"...","version":"...","gitRef":"...","metrics":{...}}

This creates a running log of benchmark results over time.

After writing both files, commit the baseline so it is a shared reference point:

git add generated/bench-check/baseline.json generated/bench-check/history.ndjson
git diff --cached --quiet -- generated/bench-check/baseline.json generated/bench-check/history.ndjson || git commit generated/bench-check/baseline.json generated/bench-check/history.ndjson -m "chore: update bench-check baseline (<gitRef>)"

git add first so that newly created files (first run) are staged; --cached then detects them correctly. Without this, git diff --quiet ignores untracked files and the baseline is never committed on the first run.

Phase 6 — Report

Skip this phase (write no report) if COMPARE_ONLY was set and no baseline existed, AND the ABORTED pre-condition was not triggered. That early-exit case was already handled in Phase 4 — writing a "BASELINE SAVED" report here would be misleading since no baseline was saved. When ABORTED, always write the ABORTED report regardless of other flags.

Write a human-readable report to generated/bench-check/BENCH_REPORT_<date>.md.

If the ABORTED pre-condition was triggered (no valid benchmark results): write a minimal report — this check MUST come before the SAVE_ONLY/first-run check, because when all benchmarks fail on a --save-baseline or first run, SAVE_ONLY would also be true but no baseline was actually saved:

# Benchmark Report — <date>

**Version:** X.Y.Z | **Git ref:** abc1234 | **Threshold:** $THRESHOLD%

## Verdict: ABORTED — no valid benchmark results

All benchmark suites failed or timed out. See Phase 1 error records for details.

## Raw Results

<!-- Error/timeout records from each suite -->

If SAVE_ONLY is set or no prior baseline existed (first run): write a shortened report — omit the "Comparison vs Baseline" and "Regressions" sections since no comparison was performed:

# Benchmark Report — <date>

**Version:** X.Y.Z | **Git ref:** abc1234 | **Threshold:** $THRESHOLD%

## Verdict: BASELINE SAVED — no comparison performed

## Raw Results

<!-- Full JSON output from each benchmark -->

Otherwise (comparison was performed): write the full report with comparison and verdict:

# Benchmark Report — <date>

**Version:** X.Y.Z | **Git ref:** abc1234 | **Threshold:** $THRESHOLD%

## Verdict: PASSED / FAILED

## Comparison vs Baseline

<!-- Full comparison table with all metrics -->

## Regressions (if any)

<!-- Detail each regression with possible causes -->

## Trend (if history.ndjson has 3+ entries)

<!-- Show trend for key metrics: build time, query time, graph size -->

## Raw Results

<!-- Full JSON output from each benchmark -->

Phase 7 — Cleanup

  1. If report was written, print its path
  2. If baseline was updated, print confirmation
  3. Print one-line summary: PASSED (0 regressions) | FAILED (N regressions) | BASELINE SAVED | ABORTED (all suites failed)

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.