Debugging performance in production has a bad reputation it mostly earns, because the usual version is someone SSHing into a live box under pressure and poking at it with tools that make it slower. It doesn't have to be that. Done well, production performance debugging is boring: you already have the traces, you read the one that's slow, you find the span that owns the time, and you reproduce it somewhere safe to fix it. What separates the stressful version from the boring one is mostly whether you set up that visibility before you needed it.
The debugging workflow
-
Identify the symptom precisely
Which route? Which user segment? Which time window? 'The app is slow' is not actionable. 'POST /api/checkout p95 went from 400ms to 2.1s after 14:00 UTC on 2026-04-12' is.
-
Pull a trace for a slow instance
Find the slowest requests in the affected time window. Open a trace. APMs break the request into spans (DB queries, cache calls, HTTP, view rendering). The largest span is your starting point.
-
Classify the bottleneck layer
App code, DB, cache, external HTTP, or view rendering. DB is a frequent answer, and N+1 queries and missing indexes are frequent DB causes. Narrow fast.
-
Reproduce locally with realistic data
Seed staging or local from anonymized production. Hit the same endpoint with similar payloads. Reproduce with Telescope or Clockwork to see the request's queries, events and timings, and add Xdebug's profiler if you need function-level detail.
-
Fix and deploy behind a flag
Use a feature flag so you can roll back instantly. Verify fix reduces p95 in production before removing the flag.
-
Document the root cause
A one-paragraph post-mortem per incident beats repeating the same discovery six months later. Include the trace URL, the fix, and the monitoring gap that let it land.
Tools by situation
| Situation | Tool | Why |
|---|---|---|
| Production trace needed | NightOwl / Nightwatch Cloud | Always-on per-request traces |
| Local call-level profiling | Xdebug + KCacheGrind | Function-level timing depth |
| Local request inspection | Telescope / Clockwork | Per-request query + event detail |
| DB query plan analysis | EXPLAIN ANALYZE | Planner decisions that matter |
| Production-safe profiling | Excimer (sampling profiler) | Low-overhead, sampled |
| Memory debugging | memory_get_peak_usage in middleware | Cheap and precise |
What you should never do in production
- Run Xdebug, which slows down every request, and much more with profiling on
- Drop into tinker on a live server. One typo and you've mass-updated a table
- Add
dd()ordump()calls, which print debug HTML into real users' responses - Turn on the database's general query log, or
DB::enableQueryLog()in a long-running worker, which grows quickly and adds load (the in-memory query log also keeps growing until the worker restarts) - Run EXPLAIN ANALYZE on write queries, which actually executes them