A measurement-first guide to investigating slow Laravel pages, queries, assets, and background tasks.
Measure before optimizing
- Record response times and identify the slow route before changing code.
- Inspect database query counts and use eager loading where it removes repeated queries.
- Add indexes only for measured query patterns and verify changes with realistic data.
- Cache stable, expensive results with an explicit invalidation strategy.
- Move suitable slow work to queues and monitor failures and retries.
- Compress and size images for their displayed dimensions.
- Build and serve minified production assets.
- Review external API latency and set sensible timeouts.
- Use production-like profiling rather than relying only on local timings.
- Run tests after each optimization to protect correctness.
Performance work is iterative: measure again after deployment and confirm that the change improved the user journey that mattered.