agentleFS
Diviner-DojoDiviner-Dojo/agent_framework_template/.claude/skills/performance-playbook/SKILL.md

performance-playbook

Skill4 starsChanged 3 months agoApache-2.0View on GitHub

Performance analysis techniques for Python/FastAPI applications. Reference when reviewing performance, optimizing code, or assessing scalability.

  • Installs packages

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are 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.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use connection pools for database connections

    line 41
  2. Distinctive:

    Don't create a new connection per request

    line 42
  3. Distinctive:

    Use pagination for list endpoints

    line 47
  4. Distinctive:

    Consider caching for frequently-read, rarely-changed data

    line 48
  5. Distinctive:

    Add indexes on columns used in WHERE clauses

    line 64
  6. Distinctive:

    Add indexes on columns used in ORDER BY

    line 65
  7. Distinctive:

    Add indexes on foreign key columns

    line 66

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

Performance Playbook

Complexity Assessment

Common Patterns and Their Costs

PatternTime ComplexityWatch For
Single loop over collectionO(n)Fine for most cases
Nested loopsO(n*m) or O(n^2)Flag if n can be large
Loop with lookup in listO(n*m)Convert list to set/dict for O(n)
SortingO(n log n)Usually acceptable
Recursive without memoizationExponentialAlways flag

Quick Assessment

For any function, ask:

  1. What is n? (size of the main input)
  2. How does execution time grow as n increases?
  3. Is this on a hot path (called frequently)?

FastAPI Performance Patterns

Async Done Right

# Good: async endpoint with async I/O
@router.get("/items")
async def list_items():
    return await db.fetch_all()

# Bad: async endpoint with sync I/O (blocks the event loop)
@router.get("/items")
async def list_items():
    return db.fetch_all_sync()  # This blocks!

Connection Pooling

  • Use connection pools for database connections
  • Don't create a new connection per request
  • Close connections properly (use context managers)

Response Optimization

  • Return only needed fields (don't expose entire DB rows)
  • Use pagination for list endpoints
  • Consider caching for frequently-read, rarely-changed data

Database Query Patterns

N+1 Query Detection

# Bad: N+1 queries
todos = db.get_all_todos()
for todo in todos:
    todo.tags = db.get_tags_for_todo(todo.id)  # N extra queries!

# Good: Single query with join
todos = db.get_all_todos_with_tags()  # JOIN in SQL

Index Usage

  • Add indexes on columns used in WHERE clauses
  • Add indexes on columns used in ORDER BY
  • Add indexes on foreign key columns
  • Monitor: if a query does a full table scan on large tables, add an index

Profiling Techniques

Built-in Timing

import time
start = time.perf_counter()
result = expensive_operation()
elapsed = time.perf_counter() - start
print(f"Operation took {elapsed:.3f}s")

Memory Profiling (when needed)

pip install memory-profiler
python -m memory_profiler script.py

Red Flags

  • Database queries inside loops
  • Loading entire tables into memory
  • Synchronous HTTP calls in async contexts
  • Unbounded list/query results (no pagination)
  • Repeated computation of the same value
  • Large objects passed by value instead of reference

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.