agentleFS
yigitcanozdemiryigitcanozdemir/full-stack-project-template/.agents/skills/optimization-audit/SKILL.md

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.

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
  1. Distinctive:

    Do not run load tests against anything but a local or explicitly provided environment.

    line 43
  2. Very specific:

    React: check whether the React Compiler is enabled before recommending useMemo / useCallback — with it on, manual memoization is usually …

    line 111
  3. Distinctive:

    Do not recommend premature micro-optimizations unless clearly justified.

    line 120
  4. Distinctive:

    Prefer high-ROI changes over clever ones.

    line 121
  5. Distinctive:

    If you cannot prove a bottleneck, label it Likely and say exactly what to measure.

    line 122
  6. Distinctive:

    If information is missing, state the assumption and continue with a best-effort analysis.

    line 123
  7. Distinctive:

    Never trade correctness for speed without stating the trade-off.

    line 126
  8. Distinctive:

    Treat duplication and dead code as optimization issues when they raise maintenance cost, bug surface, bundle size, build time or runtime …

    line 127

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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).

LayerMeasure with
Python CPU / latencypy-spy record or py-spy top against the running uvicorn; pyinstrument for one request
SQLEXPLAIN (ANALYZE, BUFFERS) on the real query; pg_stat_statements for totals; count queries per request (SQLAlchemy echo=True or an event hook)
RedisSLOWLOG GET, redis-cli --bigkeys, INFO memory, round trips per request
HTTP under loadk6 or locust — p50/p95/p99 latency and error rate, before and after
FrontendLighthouse / 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 callstokens 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

  1. Find actual or likely bottlenecks.
  2. Explain why they matter.
  3. Estimate impact (low / medium / high).
  4. Propose concrete fixes.
  5. Prioritise by ROI.
  6. 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); an await per row; sessions held open across slow external calls; pool size larger than Postgres' max_connections divided by the number of processes.
  • asyncpg behind PgBouncer in transaction mode: prepared-statement caching breaks or thrashes — statement_cache_size=0 in the connect args, or session mode.
  • FastAPI: a sync def route 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 new httpx.AsyncClient per request instead of one shared client; worker count mismatched to CPU cores.
  • Redis: KEYS or unbounded SCAN in request paths; keys without TTL; one round trip per item where a pipeline or MGET would 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:load on an island that could be client:visible / client:idle or 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.md at 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.