performance-optimizerlisted
Install: claude install-skill smicolon/ai-kit
# Performance Optimizer
Auto-detects and fixes Django ORM performance issues before they reach production.
## Activation Triggers
This skill activates when:
- Writing ORM queries
- Accessing related objects (foreign keys, M2M)
- Creating views that fetch data
- Mentioning "slow", "performance", "optimization"
- Looping over querysets
- Creating list/detail views
## Performance Targets
- ✅ NO N+1 queries
- ✅ Appropriate indexes on frequently queried fields
- ✅ Pagination for list endpoints
- ✅ `select_related()` for foreign keys
- ✅ `prefetch_related()` for reverse foreign keys and M2M
- ✅ Caching for expensive operations
## Auto-Detection Patterns
### Pattern 1: N+1 Query Detection
**❌ INEFFICIENT (N+1 query):**
```python
# Bad: 1 query for users + N queries for organizations
users = User.objects.all() # 1 query
for user in users: # N queries
print(user.organization.name) # Hits DB each time!
```
**✅ OPTIMIZED:**
```python
# Good: 2 queries total (1 for users + 1 JOIN for organizations)
users = User.objects.select_related('organization').all()
for user in users:
print(user.organization.name) # No DB hit!
```
### Pattern 2: Reverse Foreign Key N+1
**❌ INEFFICIENT:**
```python
# Bad: 1 + N queries
organizations = Organization.objects.all() # 1 query
for org in organizations: # N queries
users = org.users.all() # Hits DB each time!
print(f"{org.name}: {users.count()} users")
```
**✅ OPTIMIZED:**
```python
# Good: 2 queries total
organizations =