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
In this repository25 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adr-writingSkill
- authoring-goal-contractsSkill
- collaborating-asyncSkill
- committing-changesSkill
- cross-agent-dispatchSkill
- documenting-decisionsSkill
- feature-status-registrySkill
- grill-meSkill
- grill-yourselfSkill
- handling-micro-fixesSkill
- multi-instance-dispatchSkill
- notifying-the-developerSkill
- orchestrating-goal-loopsSkill
- orchestrating-lean-dispatchSkill
- python-project-patternsSkill
- recovering-from-failuresSkill
- running-build-checkpointsSkill
- searching-prior-artSkill
- security-checklistSkill
- selecting-review-gatesSkill
- severity-calibrationSkill
- syncing-framework-docsSkill
- testing-playbookSkill
- wrapping-up-sessionsSkill
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
- Distinctive: line 41
Use connection pools for database connections
- Distinctive: line 42
Don't create a new connection per request
- Distinctive: line 47
Use pagination for list endpoints
- Distinctive: line 48
Consider caching for frequently-read, rarely-changed data
- Distinctive: line 64
Add indexes on columns used in WHERE clauses
- Distinctive: line 65
Add indexes on columns used in ORDER BY
- Distinctive: line 66
Add indexes on foreign key columns
≈ “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.
Files
Performance Playbook
Complexity Assessment
Common Patterns and Their Costs
| Pattern | Time Complexity | Watch For |
| Single loop over collection | O(n) | Fine for most cases |
| Nested loops | O(n*m) or O(n^2) | Flag if n can be large |
| Loop with lookup in list | O(n*m) | Convert list to set/dict for O(n) |
| Sorting | O(n log n) | Usually acceptable |
| Recursive without memoization | Exponential | Always flag |
Quick Assessment
For any function, ask:
- What is n? (size of the main input)
- How does execution time grow as n increases?
- 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 SQLIndex 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.pyRed 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
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.

