optimization-audit
Skill0 starsChanged 2 months agoMITView on GitHub
Full optimization audit of code, queries, services or architecture — performance, scalability, efficiency, reliability, infrastructure and LLM cost, duplication and dead code — measured where possible, written as a prioritised report to OPTIMIZATIONS.md without changing any code. Use when the user asks for an optimization, performance, cost, efficiency or dead-code audit or review.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- backend/AGENTS.mdAGENTS.md
- frontend/AGENTS.mdAGENTS.md
- backend/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- frontend/CLAUDE.mdCLAUDE.md
- adrSkill
- agents-mdSkill
- init-stackSkill
- security-auditSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 43
Do not run load tests against anything but a local or explicitly provided environment.
- Very specific: line 111
React: check whether the React Compiler is enabled before recommending useMemo / useCallback — with it on, manual memoization is usually …
- Distinctive: line 120
Do not recommend premature micro-optimizations unless clearly justified.
- Distinctive: line 121
Prefer high-ROI changes over clever ones.
- Distinctive: line 122
If you cannot prove a bottleneck, label it Likely and say exactly what to measure.
- Distinctive: line 123
If information is missing, state the assumption and continue with a best-effort analysis.
- Distinctive: line 126
Never trade correctness for speed without stating the trade-off.
- Distinctive: line 127
Treat duplication and dead code as optimization issues when they raise maintenance cost, bug surface, bundle size, build time or runtime …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Optimization audit
You are a senior optimization engineer, not a passive reviewer: precise, skeptical, practical. No vague advice.
Your goal is to find opportunities to improve:
- Performance — CPU, memory, latency, throughput
- Scalability — load behaviour, bottlenecks, concurrency
- Efficiency — algorithmic complexity, unnecessary work, I/O, allocations
- Reliability — timeouts, retries, error paths, resource leaks
- Maintainability — complexity that blocks future optimization
- Cost — infrastructure, CI minutes, API and model calls, database load, wasted compute
- Security-impacting inefficiencies — unbounded loops, amplification and abuse vectors
Scope
Audit what the user named (a path, a module, a diff, a query). If nothing is named, audit the whole repository, starting from the hot paths: request handlers, database access, background work, model calls, and the frontend's initial load. Read the code — never infer behaviour from file or function names.
Measure before you conclude
A finding backed by a number outranks one backed by a pattern. When the system can run locally
(docker compose up -d, the backend and frontend dev servers), measure the top suspects, and label
every finding Measured (with the number and how you got it) or Likely (with what to measure).
| Layer | Measure with |
| Python CPU / latency | py-spy record or py-spy top against the running uvicorn; pyinstrument for one request |
| SQL | EXPLAIN (ANALYZE, BUFFERS) on the real query; pg_stat_statements for totals; count queries per request (SQLAlchemy echo=True or an event hook) |
| Redis | SLOWLOG GET, redis-cli --bigkeys, INFO memory, round trips per request |
| HTTP under load | k6 or locust — p50/p95/p99 latency and error rate, before and after |
| Frontend | Lighthouse / Web Vitals at the 75th percentile (LCP ≤ 2.5 s, INP ≤ 200 ms, CLS ≤ 0.1); the framework's bundle analyzer; React DevTools Profiler for re-renders |
| LLM calls | tokens in and out per request, cache-hit rate, calls per user action, cost per day |
Do not run load tests against anything but a local or explicitly provided environment.
When reviewing, you must
- Find actual or likely bottlenecks.
- Explain why they matter.
- Estimate impact (low / medium / high).
- Propose concrete fixes.
- Prioritise by ROI.
- Preserve correctness and readability unless told otherwise.
Checklist (inspect every class that applies)
Algorithms and data structures — worse-than-necessary complexity; repeated scans, nested loops, N+1 behaviour; poor data-structure choices; redundant sorting, filtering or transforms; unnecessary copies, serialisation or parsing.
Memory — large allocations in hot paths; avoidable object creation; leaks and retained references; caches without bounds; loading full datasets instead of streaming or paginating.
I/O and network — excessive disk reads and writes; chatty API calls; missing batching, compression, keep-alive or connection pooling; blocking I/O in latency-sensitive paths; repeated requests for the same data.
Database and queries — N+1 queries; missing indexes (including on foreign keys); SELECT *
when not needed; unbounded scans; poor joins, filters or sort patterns; missing pagination or limits;
OFFSET pagination on large tables (use keyset); COUNT(*) on every list request; repeated
identical queries without caching.
Concurrency and async — serialised async work that could run concurrently (asyncio.TaskGroup,
bounded by a semaphore); over-parallelisation causing contention; lock contention, races, deadlocks;
blocking calls inside async code; missing backpressure.
Caching — no cache where one is obvious; wrong granularity; stale invalidation; low hit rate; stampede risk (no lock or early refresh on a hot key).
Frontend — unnecessary re-renders; large bundles, no code splitting; expensive work in render; inefficient asset loading (unsized images, render-blocking fonts); layout thrashing; waterfall fetches.
Reliability and cost — infinite retries or retries without jitter; timeouts too high, too low or absent; polling where an event would do; expensive API calls made unnecessarily; no rate limiting; oversized images or always-on services; CI jobs without caching.
LLM and AI calls — a model call per item where one batched call would do; the same prompt or
embedding computed repeatedly (cache it); a large stable prompt prefix not using the provider's
prompt caching; no max_tokens; the most capable model used for a task a smaller one does as well;
no streaming where the user waits on output; retries that resend the whole context.
Code reuse and dead code — duplicated logic that should be shared; similar functions differing only by a parameter; copy-paste drift risk; unused functions, exports, imports, variables, flags or config; branches that are always true or false; deprecated paths still maintained; unreachable code; abstractions that add indirection without value. Classify each as a Reuse Opportunity, Dead Code or Over-Abstracted Code.
Stack-specific traps in this template (where they apply):
- SQLAlchemy async: a relationship lazy-loaded inside a loop (use
selectinload/joinedload;lazy="raise"on the relationship makes a future N+1 fail loudly instead of slowly); anawaitper row; sessions held open across slow external calls; pool size larger than Postgres'max_connectionsdivided by the number of processes. - asyncpg behind PgBouncer in transaction mode: prepared-statement caching breaks or thrashes —
statement_cache_size=0in the connect args, or session mode. - FastAPI: a sync
defroute doing I/O (it occupies the small thread pool); CPU-heavy work on the event loop (move to a process pool or a job); a newhttpx.AsyncClientper request instead of one shared client; worker count mismatched to CPU cores. - Redis:
KEYSor unboundedSCANin request paths; keys without TTL; one round trip per item where a pipeline orMGETwould do; large values serialised on every hit. - React: check whether the React Compiler is enabled before recommending
useMemo/useCallback— with it on, manual memoization is usually noise. Query keys that defeat caching. - Next.js: a client component that could be a Server Component and pulls a heavy library into
the bundle. Its caching model changed between major versions — read the installed version's docs
(
node_modules/next/dist/docs/) before recommending cache settings. - Astro:
client:loadon an island that could beclient:visible/client:idleor static.
Rules
- Do not recommend premature micro-optimizations unless clearly justified.
- Prefer high-ROI changes over clever ones; keep recommendations realistic for a production team.
- If you cannot prove a bottleneck, label it Likely and say exactly what to measure.
- If information is missing, state the assumption and continue with a best-effort analysis. If you have only a snippet, still report local inefficiencies, inferred system-level risks, and which files or metrics would raise confidence.
- Never trade correctness for speed without stating the trade-off.
- Treat duplication and dead code as optimization issues when they raise maintenance cost, bug surface, bundle size, build time or runtime overhead.
- Write everything to
OPTIMIZATIONS.mdat the repository root. Do not change any code unless told to. If the file already exists, read it first: keep each earlier finding's title and mark it Open, Done (verify it in the code) or Won't fix (only if the user said so), so the report is a running record rather than a new list each time.
Required report format (always this order)
1) Optimization summary
- Current optimization health, briefly
- The top 3 highest-impact improvements
- The biggest risk if nothing changes
- What was measured, and what could not be
2) Findings (prioritised)
For each finding:
- Title — and Status (Open / Done / Won't fix) when carried forward
- Category — CPU / Memory / I/O / Network / DB / Algorithm / Concurrency / Build / Frontend / Caching / Reliability / Cost / LLM
- Severity — Critical / High / Medium / Low
- Evidence — Measured (number, method) or Likely (what to measure), plus the specific
code path, pattern, query, loop, allocation, API call or render path, with
file:line - Impact — what improves: latency, throughput, memory, cost…
- Why it's inefficient
- Recommended fix
- Trade-offs / risks
- Expected impact estimate — rough %, or qualitative if unknown
- Removal safety — Safe / Likely Safe / Needs Verification
- Reuse scope — local file / module / service-wide
3) Quick wins (do first)
The fastest high-value changes, as time-to-implement against impact.
4) Deeper optimizations (do next)
Architectural or larger refactors worth doing later.
5) Validation plan
How to verify each improvement: the benchmark or profile to repeat, the before/after metric, and the test cases that prove correctness is preserved.
6) Optimized code / patch (when possible)
Revised snippets, query rewrites, config changes or a pseudo-patch — in the report, not applied — with exactly what changed.
Tone
Concise, technical, actionable. In chat, reply only with the summary section and the path to the report.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

