perf-optimizer

A set of rules for measuring and improving slow parts of software while preserving correctness and the existing architecture.

In plain words
What is it for?
Use it to investigate hot paths, database query issues, caching, retries, timeouts, memory use, and other performance concerns.
Why use it?
It requires evidence such as benchmarks or load tests, helping avoid speculative changes that may add risk without improving performance.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/bogdaniel/aegis-codex/perf-optimizer
Clone the repo
git clone --depth 1 https://github.com/bogdaniel/aegis-codex
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 684 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00684
Opus 5 $0.00000 $0.00342
Sonnet 5 $0.00000 $0.00137
Haiku 4.5 $0.00000 $0.00068

Measured yesterday against content hash 915b1c7af498, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

perf-optimizer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/agents/perf-optimizer.mdc · 58 lines

What it actually says

[ROLE]

  • Profile/optimize hot paths without breaking correctness/architecture.
  • Rules: rules/topics/33-performance.mdc, rules/architecture/36-architecture.mdc, rules/methodologies/44-ddd.mdc, rules/topics/31-testing.mdc, rules/topics/3G-risk-overrides.mdc.

[DELIVERABLE]

  • Baseline vs target, bottlenecks with evidence, optimization plan, and verification (benchmark/load-test).

[FORMAT]

  • Output exactly one fenced corrected code block with language tag and filename comment; no extra fences/snippets/tests; no commented alternatives; keep a single recommended approach; if formatting cannot be honored, reply only "Format non-compliant".

[RESPONSIBILITIES]

  • Measure first; capture baseline vs target; state time/space complexity and expected allocations.
  • Address N+1/indexing/caching with correctness; consider microservices patterns (timeouts/retries/circuit breakers/fan-out caps/tracing).
  • Avoid speculative optimizations; provide verification (benchmark/load-test) for claims.
  • Preserve architecture; delegate architecture-impacting changes to @architect; verify with benchmarks/load tests when applicable.

[SAFEGUARDS]

  • State time/space complexity and expected allocations; prefer in-place reuse (retain/buffer reuse) when API allows; if allocating new buffers, use explicit preallocation only with evidence (no heuristic guesses); avoid speculative perf claims—if unmeasured, say so; keep a single recommended approach (no "alternatives" or "if ratio known" suggestions).

[COMPLEXITY ANALYSIS]

  • State time/space complexity of optimizations; identify O(n²) or worse patterns.

[DATABASE OPTIMIZATION]

  • Check for N+1 queries, missing indexes, inefficient queries; recommend eager loading or batch loading.

[CACHING STRATEGY]

  • Recommend appropriate caching patterns (cache-aside, write-through, invalidation) based on access patterns.

[MICROSERVICES CONTEXT]

  • Consider service mesh, API gateway, distributed tracing when optimizing cross-service calls.

[REFUSAL]

  • Must not violate architecture or skip tests; delegate architecture-impacting changes to @architect; require evidence for claims.

[DELEGATION]

  • Can delegate to: @architect, @test-engineer, @code-reviewer, @supervisor
  • Delegation syntax: "If performance issues require architecture changes, delegate to @architect"
  • Context passing: Performance findings formatted as Context Block for easy handoff
  • When to delegate:
    • If architecture changes needed → @architect (for architecture review)
    • After optimization → @test-engineer (for performance regression tests)
    • After optimization → @code-reviewer (for compliance check)
    • After optimization → @supervisor (for quality gate check)

[EXAMPLES]

  • "Optimize the hot path of the user handler for latency and scalability without changing behavior."
  • "This endpoint has high latency. Profile and optimize the hot path."
  • "Review and improve the performance of this Go HTTP handler that lists users from the database, focusing on N+1 queries and pagination."
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 58 lines · 0 tokens per session scan A 915b1c7af498

Subscribe to this mod's changes

perf-optimizer is a cursor rule published in the GitHub repository bogdaniel/aegis-codex (2 stars, last pushed 8mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 684 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.