Hasina Razafintsalama

Hasina RAZAFINTSALAMA

← Back to Blog
Backend

Optimizing Laravel Performance: Beyond the Basics

N+1 queries and missing indexes get all the attention. Here are the Laravel-specific tools,Octane, Horizon, targeted caching,that make the real difference in production.

2026-07-15·8 min

The audit checklist covers the universal performance killers,N+1 queries, missing indexes, unbounded results. This article goes further: the Laravel-specific tools that squeeze out the next level of performance once the basics are fixed.

Laravel Octane: keep the framework booted between requests

Traditional PHP-FPM boots the entire framework,service providers, config, routes,on every single request. Octane (running on Swoole or RoadRunner) keeps the application in memory between requests, cutting response time significantly under load. The trade-off: you must avoid state leaking between requests, no mutable static properties, careful handling of singletons bound in the container.

php
// config/octane.php
'server' => 'swoole',
'warm' => [
    ...Octane::defaultServicesToWarm(),
],

// Dangerous with Octane: static state persists across requests
class ReportCache
{
    private static array $cache = []; // leaks between requests, avoid
}

Targeted caching with Cache::remember and tags

Cache expensive, repeated queries,not every query. Cache tags let you invalidate a specific slice of cached data without flushing everything, which matters once you have more than a handful of cached values.

php
$topProducts = Cache::tags(['products', 'dashboard'])
    ->remember('top-products', now()->addMinutes(30), function () {
        return Product::withCount('orders')
            ->orderByDesc('orders_count')
            ->limit(10)
            ->get();
    });

// Invalidate only the products slice, not the whole cache
Cache::tags(['products'])->flush();

Horizon: visibility into your queues

Queue workers fail silently more often than you would expect,a job throws, retries three times, then disappears into the failed_jobs table nobody checks. Horizon gives you real-time metrics on throughput, wait time, and failures, plus configurable balancing strategies between queues.

Telescope and Debugbar: find the bottleneck before guessing

Use Telescope in staging to inspect queries, requests, and jobs in detail,never leave it enabled unauthenticated in production. Debugbar is lighter-weight and useful locally to catch N+1 queries and slow requests during development, before they reach staging.

Measure before optimizing. Octane will not fix N+1 queries, and caching will not fix a missing index. Profile first with Telescope, fix the root cause, then reach for Octane and caching for the remaining gains.

A realistic optimization order

  • Fix N+1 queries and missing indexes first,biggest return, covered in the audit checklist.
  • Add targeted caching for expensive, repeated queries.
  • Move heavy work to queues, monitored with Horizon.
  • Only then consider Octane,it multiplies the benefit of an already-optimized app rather than fixing a slow one.

Need help with this topic? Technical Audit

Discover this service