Ask Claude to Find Performance Bottlenecks by Reading Your Code Logic
Profilers tell you what's slow. Claude tells you why — by reading the code and identifying algorithmic issues, unnecessary work, and architectural anti-patterns that cause slowness before you even run the profiler.
Read the API endpoints in src/controllers/ and identify performance problems.
Look for N+1 queries, missing pagination, expensive operations in request
handlers, and algorithms that scale poorly with data size.
Claude traces the execution path for each endpoint and flags issues:
- Functions that loop over database results and make a query per item (N+1)
- Endpoints that load entire collections when they only need a count
- Synchronous operations that should be queued (sending emails, generating PDFs)
- Nested loops that become quadratic as data grows
- Missing database indexes implied by the query patterns
Target specific performance concerns:
# Database query analysis
Read the Eloquent/ActiveRecord queries in src/repositories/ and find
any that will get slower as the table grows. Flag missing indexes,
full table scans, and queries that load more data than needed.
# API response time
Which endpoints do the most work? Rank them by estimated complexity
and flag any that make external API calls synchronously.
# Algorithmic complexity
Find any functions in src/lib/ with nested loops over collections.
Which ones are O(n²) or worse? Can any be optimized with Maps or Sets?
# Unnecessary computation
Find places where the same expensive computation runs multiple times
per request — duplicate database queries, redundant calculations,
or data that could be cached between calls.
After finding issues, ask Claude to fix the worst ones:
Fix the top 3 performance issues you found. Add eager loading for the
N+1 queries, add pagination to the user list endpoint, and move the
PDF generation to a background job.
A profiler measures what happened. Code analysis predicts what will happen as your data grows — let Claude find the O(n²) hiding inside that innocent-looking forEach.
via Claude Code
Log in to leave a comment.
When a page takes five seconds to load or an API endpoint times out under load, tell Claude which route is slow and it traces the entire code path — controller, services, queries, loops — identifying N+1 queries, redundant computations, missing indexes, and cacheable operations, then fixes each bottleneck.
Flaky tests are maddening — they pass locally, fail in CI, pass again when you retry. Tell Claude to read the test, identify the source of non-determinism — timing issues, shared state, date dependencies, or order-dependent setup — and fix the root cause so the test is reliably green or reliably red.
When your app throws an error, don't just Google the message — paste the full stack trace into Claude Code. It reads the trace, opens the referenced files in your codebase, follows the call chain, and pinpoints the actual root cause instead of just explaining the symptom.