How fast is Laravel compared to other PHP frameworks? Benchmark results in requests-per-second (check methodology section to understand how they were conducted) prove it to be times slower than all others:
Framework | test/html | Faster | test/json | Faster |
Lucinda | 8449.55 | + 48.49 X | 9243.01 | + 52.16 X |
Symfony | 1859.40 | + 10.67 X | 2105.95 | + 11.88 X |
CodeIgniter | 1238.57 | + 7.11 X | 1284.06 | + 7.25 X |
Laravel | 174.26 | 177.20 |
Why is it so unbelievably sluggish, over 10 times slower than its main competitor (Symfony)? The main culprit is over-programming and loads of logic inside that should only ran when required (as improvements by tweaks below demonstrate).
One of the things that contributes to slowness is the fact that on every request, framework opens a session and saves a new file. This questionable decision makes framework twice slower but it can be easily corrected in app/http/Kernel.php by commenting following lines:
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
// \Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
// \Illuminate\View\Middleware\ShareErrorsFromSession::class,
// \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
Once that is done, framework becomes twice faster, but still in desperate need of more tweaks. Results in requests per second:
Framework | HTML Rendering | JSON Rendering |
Laravel (tweak #1) | 386.37 | 376.34 |
Laravel (factory settings) | 174.26 | 177.20 |
Let us tweak laravel to the max and keep only services strictly required in MVC. This means emptying all middleware in app/http/Kernel.php so it becomes:
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
protected $middleware = [];
protected $middlewareGroups = [
'web' => [],
'api' => [],
];
protected $routeMiddleware = [];
}
then modifying $providers and $aliases in config/app.php to become:
'providers' => [
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
App\Providers\RouteServiceProvider::class,
],
'aliases' => [],
Even with such drastic (unrealistic) changes, results only improve marginally:
Framework | HTML Rendering | JSON Rendering |
Laravel (tweak #2) | 443.73 | 443.16 |
Laravel (tweak #1) | 386.37 | 376.34 |
Laravel (factory settings) | 174.26 | 177.20 |
Trying to optimize Laravel for performance is a job destined for failure. It seems its developers had zero performance concerns on their product: loads of logic is bundled for no reason and framework itself is massively over-programmed. All of these make Laravel incompatible with performance, so caching or related solutions will be your only viable options.