Performance profile

From weisser-dev/awesome-opencode · View interactive version

Performance profile is an AI agent skill from the GitHub repository weisser-dev/awesome-opencode. Analyze code for performance hotspots including complexity, N+1 queries, memory allocations, and caching opportunities

How to use this skill

Skill file

What I do

When to use me

Use this skill when you need to:

Process

  1. Identify the scope: Determine what to profile
  1. Analyze algorithmic complexity: Check for inefficient patterns
  1. Detect N+1 queries: Scan database access patterns
  1. Check memory patterns: Look for allocation hotspots
  1. Evaluate caching: Identify caching opportunities
  1. Produce optimization plan: Prioritize by impact and effort

Anti-Pattern Catalog

N+1 Query Pattern

# BAD: N+1 queries
users = db.query("SELECT * FROM users")
for user in users:
    orders = db.query(f"SELECT * FROM orders WHERE user_id = {user.id}")

# GOOD: Single query with JOIN or batch
users_with_orders = db.query("""
    SELECT u.*, o.*
    FROM users u
    LEFT JOIN orders o ON o.user_id = u.id
""")

Quadratic Loop

// BAD: O(n * m) lookup
for (const order of orders) {
  const user = users.find(u => u.id === order.userId); // O(n) each time
}

// GOOD: O(n + m) with hash map
const userMap = new Map(users.map(u => [u.id, u]));
for (const order of orders) {
  const user = userMap.get(order.userId); // O(1) each time
}

Unbounded Accumulation

// BAD: Loading entire result set into memory
List<Record> allRecords = repository.findAll(); // millions of rows

// GOOD: Stream or paginate
try (Stream<Record> stream = repository.streamAll()) {
    stream.forEach(record -> process(record));
}

Missing Memoization

// BAD: Recomputing expensive result
function getReport(params: Params) {
  return expensiveComputation(params); // called repeatedly with same params
}

// GOOD: Cache the result
const cache = new Map<string, Report>();
function getReport(params: Params) {
  const key = JSON.stringify(params);
  if (!cache.has(key)) {
    cache.set(key, expensiveComputation(params));
  }
  return cache.get(key);
}

Optimization Plan Format

## Performance Optimization Plan

### Summary
- **Scope:** Order processing pipeline
- **Current p95 latency:** 2.4s
- **Target p95 latency:** 500ms

### Findings (Priority Order)

| # | Issue | Impact | Effort | Location |
|---|-------|--------|--------|----------|
| 1 | N+1 query in order loader | High | Low | `src/orders/loader.ts:34` |
| 2 | Quadratic user lookup | High | Low | `src/orders/enrich.ts:67` |
| 3 | No caching on product catalog | Medium | Medium | `src/products/service.ts:12` |
| 4 | Large JSON serialization in loop | Low | Low | `src/orders/export.ts:89` |

### Detailed Recommendations

#### 1. N+1 query in order loader (High Impact, Low Effort)
**Current:** 1 query per order to fetch items (100 orders = 101 queries)
**Fix:** Use batch query with `WHERE order_id IN (...)`
**Expected improvement:** ~80% latency reduction for this path

Severity Assessment

| Level | Criteria |

|-------|----------|

| Critical | Causes timeouts, OOM, or system instability under normal load |

| High | Noticeable latency (>1s) on common user operations |

| Medium | Suboptimal but functional; affects throughput under high load |

| Low | Minor inefficiency; optimize if effort is minimal |

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.