Performance Profiler
Identify performance anti-patterns in code: N+1 queries, unbounded loops, missing pagination, memory leaks, and inefficient algorithms through static analysis.
Guiding Principle
"Performance is a feature. Users measure your software in milliseconds, not function points."
Procedure
Step 1 — Query Pattern Analysis
- Grep for database queries inside loops (N+1 pattern).
- Identify missing eager loading / includes / joins in ORM queries.
- Check for
SELECT * usage instead of column-specific queries.
- Find queries without pagination or limits on unbounded result sets.
- Document each N+1 candidate with file, line, and estimated impact
[HECHO].
Step 2 — Algorithm & Data Structure Review
- Identify nested loops operating on collections (O(n^2) or worse).
- Check for repeated computations that should be memoized or cached.
- Find synchronous blocking operations in async contexts.
- Detect large object serialization/deserialization in hot paths.
- Flag string concatenation in loops instead of builder/join patterns.
Step 3 — Resource Usage Analysis
- Identify unbounded in-memory collections (arrays/maps that grow without limit).
- Check for missing connection pool configuration (database, HTTP clients).
- Find file handles, streams, or connections that may not be properly closed.
- Detect missing timeouts on external calls (HTTP, database, queue).
- Assess caching strategy: what's cached, expiration policies, invalidation
[INFERENCIA].
Step 4 — Performance Report
- Prioritize findings by estimated user impact (latency, throughput, resource cost).
- Classify each finding: query optimization, algorithm improvement, resource management, caching.
- Provide specific code-level remediation for each finding.
- Estimate improvement potential (e.g., "N+1 fix could reduce query count from ~100 to 2").
Quality Criteria
- N+1 patterns identified with specific ORM calls and loop context
[HECHO]
- Algorithm complexity noted with Big-O notation
- Resource leaks identified with specific file handles or connections
- Remediation includes concrete code suggestions
Anti-Patterns
- Only looking at database queries while ignoring algorithmic inefficiency
- Optimizing code that isn't on the hot path (premature optimization)
- Recommending caching without considering invalidation complexity
- Ignoring async/await misuse that causes sequential execution of parallel-capable work