Performance review

From athola/claude-night-market · View interactive version

Performance review is an AI agent skill from the GitHub repository athola/claude-night-market. Detects time and space complexity hotspots via AST scan. Use when code feels slow, before performance-sensitive merges, or to find O(n²) regressions.

How to use this skill

Skill file

Performance Review

Static-analysis review of time and space complexity hotspots.

The skill runs in three escalating tiers. Tier 1 uses Python's

stdlib ast and always runs. Tier 2 uses tree-sitter to extend

detection to JS/TS, Go, Rust, Java, and C/C++ when the tiers

extra is installed. Tier 3 walks the gauntlet call graph forward

from each finding and raises its severity one step when a callee

holds a hotspot, and runs when the gauntlet plugin is importable

and a .gauntlet/graph.db exists. Without them, Tiers 2 and 3

no-op and Tier 1 still produces findings on Python source.

Quick Start

/performance-review                  # scan changed files
/performance-review path/to/file.py  # scan one file
/performance-review --tier 1         # force Tier 1 only

Programmatic use:

from pensive.skills.performance_review import PerformanceReviewSkill

skill = PerformanceReviewSkill()
result = skill.analyze(context, "src/module.py")
for f in result.issues:
    print(f"[{f.severity}] {f.file}:{f.line} {f.message}")

When To Use

profiler.

are common.

When NOT to Use

time on real data). Use Skill(parseltongue:python-performance)

instead: that skill drives cProfile, py-spy, and benchmarks.

Skill(pensive:code-refinement) whose algorithm-efficiency

module covers broader optimization patterns. This skill

detects, and that skill teaches.

SIMD, strength reduction) is worth keeping: use

Skill(leyline:loop-optimization) for the hand-vs-compiler rule.

This skill flags hotspot shapes and leaves the transform choice

to that skill.

queue placement): use Skill(pensive:architecture-review).

Required Progress Items

  1. perf-review:context-established
  2. perf-review:scan-complete
  3. perf-review:findings-categorized
  4. perf-review:integration-checked
  5. perf-review:report-generated
  6. perf-review:findings-verified

Workflow

Step 1: Context (`perf-review:context-established`)

git diff --name-only. If invoked with a path, scope to that.

files need the tiers extra for Tier 2 coverage.

Step 2: Tier 1 AST scan (`perf-review:scan-complete`)

Load modules/time-complexity.md for the time-side patterns and

modules/space-complexity.md for space-side. Each module

documents the AST shape of every detector.

Alongside the automated scan, load

modules/memory-allocation-lenses.md and apply its three

manual lenses (unbounded external-source collections, hot-path

recompute, serial blocking I/O) by reading the target files.

For each Python target file, call:

from pensive.skills.performance_review import PerformanceReviewSkill

result = PerformanceReviewSkill().analyze(context, path)

The visitor walks the AST once and emits ReviewFinding records.

Step 3: Categorize and rank (`perf-review:findings-categorized`)

Group findings by severity:

(T3, T4, S1, S3).

Within a severity, sort by file then line. Suppress findings

the user has explicitly marked acceptable (TODO/comment

markers) at module-load time of the target.

Step 4: Tier 2/3 enrichment (`perf-review:integration-checked`)

Load modules/gauntlet-integration.md for the contract.

If tree_sitter_language_pack is importable, run Tier 2 on

non-Python files that were skipped at Step 2. If gauntlet is

importable and a .gauntlet/graph.db exists in the scanned

file's directory or any parent, run Tier 3 to upgrade severities

based on hotspots in transitive callees.

Without the extra, this step is a no-op and the report notes

"Tier 2/3 not available: install pensive with the tiers extra

for multi-language and call-chain coverage." A file that

tree-sitter cannot parse adds a warning and yields no Tier 2

findings.

Step 5: Report (`perf-review:report-generated`)

Emit a markdown report:

## Performance Review: <target>

### HIGH (<count>)
- src/foo.py:42: Nested loop over the same iterable 'items'.
  Suggestion: sort + two pointers, or hash-set membership.

### MEDIUM (<count>)
- ...

### LOW (<count>)
- ...

Tier coverage: 1 (always) | 2 (gauntlet ✓/✗) | 3 (graph ✓/✗)

The report is informational. Apply fixes via

Skill(pensive:code-refinement) or hand-merge.

Tiered Analysis

| Tier | Source | When it runs | What it covers |

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

| 1 | stdlib ast | Always (Python source only) | T1-T6, S1-S3 |

| 2 | tree_sitter_language_pack | When importable, non-Python files | T1, T2, S1 on JS/TS, Go, Rust, Java, C/C++ (Java and C: T1 only) |

| 3 | gauntlet.graph.GraphStore | When importable and .gauntlet/graph.db is found above the file | One-step severity upgrade when a CALLS-reachable function holds a hotspot |

Output Format

Findings use the shared ReviewFinding dataclass from

pensive.skills.base:

ReviewFinding(
    file="src/module.py",
    line=42,
    severity="HIGH",  # LOW | MEDIUM | HIGH | CRITICAL
    category="time",  # time | space
    message="Nested loop over the same iterable 'items'.",
    suggestion="Sort + two pointers, or hash-set membership.",
    anchor="verbatim source text at file:line",
    code_snippet="",
)

This shape matches every other pensive review skill, so the

findings can flow into Skill(pensive:unified-review) without

translation.

Cross-Plugin Dependencies

| Dependency | Required? | Effect when missing |

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

| tree_sitter_language_pack | Optional (tiers extra) | Tier 2 returns []; Python coverage unchanged |

| gauntlet.graph.GraphStore | Optional (gauntlet plugin, not on PyPI) | Tier 3 returns []; severities are not upgraded |

The optional-import contract follows the precedent in

plugins/leyline/src/leyline/tokens.py:34-42: try-import to a

module-level sentinel, then early-return on None inside each

tier helper. plugins/gauntlet/hooks/precommit_gate.py:35-40

is the boolean-flag variant of the same shape. See

modules/gauntlet-integration.md for the exact code shape.

Supporting Modules

shapes.

fallback semantics, examples.

charts with kuva (criterion, pytest-benchmark, ad-hoc tables).

Covers when chart evidence satisfies proof-of-work requirements.

(not AST detectors) for unbounded collections fed from

external sources, hot-path recompute that should be memoized,

and serial blocking I/O over unbounded sets. Apply by reading

the code. The detector-test rule in Testing does not cover

these because nothing is automated.

Verification

A perf-review finding is only useful if the caller can confirm it

is real. Use this checklist before treating any finding as worth

fixing:

  1. Reproduce under a profiler. Run cProfile, py-spy, or the

language-specific equivalent on the hotspot. The findings

pinpoint AST shapes, and the profiler validates the runtime impact.

  1. Re-run the failing benchmark. If benches/ exists, the

hotspot should show up in benchmark numbers as well as AST

scans.

  1. Compare numbers before and after the proposed fix. The fix

is wrong if numbers do not move. Capture both timings as

evidence references like [E1] (before) and [E2] (after).

When 3+ data points exist, render a kuva chart and attach it

to the PR (see modules/kuva-visualization.md).

  1. Sample two or three reported hotspots manually. Findings can

be true at the AST level and false at the call-graph level

when callers short-circuit. Manual sampling catches that.

The Skill(imbue:proof-of-work) discipline applies: claims like

"the hotspot is fixed" require measured evidence.

Testing

A test file already exists at

plugins/pensive/tests/skills/test_performance_review.py covering

the AST-shape detectors. Two rules for changes here:

added to the modules ships with a test that has the smallest

AST sample exercising it.

the skill stops firing on a shape that used to look hot, the

reason should appear as a test case so the regression is

discoverable later.

The Iron Law applies: a new detector without a failing test first

is a request to skip TDD on a code-analysis component, which is

exactly the place where TDD pays off most.

Verify Findings Are Grounded (`perf-review:findings-verified`)

Write findings to .review/findings.json, run the citation verifier

(Skill(imbue:review-core) Step 5), and drop or label UNVERIFIED any

the verifier rejects.

Exit Criteria

suggestion the caller can act on.

detectors have been run, and tier coverage is reported.

contracts honor the optional-import sentinel: missing

modules return [] rather than raising.

fails before the detector exists, and each removed false

positive ships with a regression test.

translation when invoked from the unified entry point.

confirmed by citation_verifier.py (exit 0), or unverified

findings were dropped or labeled UNVERIFIED

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.