10 Simplified Laravel 10 Performance Hacks You Can Use Today
After much research and fine tuning, Laravel 10 is fast out of the box, but with just a few simple tweaks, you can make your app even faster — and the best part! You don’t need to be a Laravel expert to do it.
Whether you're building your first Laravel project or deploying to production, these 10 beginner-friendly performance hacks will help speed things up without breaking a sweat.
Let’s dive in! ♂️
1. Use Route Caching (Speed Up Routing)
Laravel compiles your routes into a single file, making routing lightning-fast.
✅ Use this command in production:
php artisan route:cache
Remember to clear the route cache if you update routes:
php artisan route:clear
2. Use Config Caching (Load All Configs at Once)
Instead of loading multiple config files one by one, cache everything into a single file.
php artisan config:cache
To clear it:
php artisan config:clear
Always re-run this after updating .env
or any config file.
3. Compile Blade Views (Faster Templating)
Laravel can precompile your Blade templates so it doesn’t compile them every time a user visits a page.
php artisan view:cache
To clear it:
php artisan view:clear
4. Cache Heavy Database Queries
If you’re fetching data that doesn’t change often, cache it instead of hitting the DB every time.
$posts = Cache::remember('active_posts', 600, function () {
return Post::where('status', 'active')->get();
});
This caches the result for 10 minutes (600 seconds).
5. Use Eager Loading to Avoid N+1 Problem
Instead of loading related data one by one (slow), load everything in one go (fast!).
❌ Bad (N+1 problem):
$users = User::all();
foreach ($users as $user) {
echo $user->profile->bio;
}
✅ Good (Eager loading):
$users = User::with('profile')->get();
foreach ($users as $user) {
echo $user->profile->bio;
}
6. Add Indexes to Speed Up Search
If you often filter or search using a column (e.g., email), indexing helps a lot.
In your migration:
Schema::table('users', function (Blueprint $table) {
$table->index('email');
});
Without indexes, your database will scan every row = slow!
7. Use the Latest PHP Version with OPcache
Using the latest PHP version (like PHP 8.3) and enabling OPcache gives Laravel a big performance boost.
Check if OPcache is enabled in your php.ini
:
opcache.enable=1
opcache.enable_cli=1
✅ You can check your current version with:
php -v
8. Optimize Composer Autoload
For faster autoloading in production, optimize the Composer classmap:
composer install --optimize-autoloader --no-dev
Or if already installed:
composer dump-autoload -o
This loads classes faster by avoiding directory scanning.
9. Use Lazy Collections for Large Data
Handling thousands of records? Use cursor()
to avoid memory overload:
foreach (User::cursor() as $user) {
echo $user->email;
}
This reads records one-by-one instead of loading everything into memory.
10. Use Queues for Time-Consuming Tasks
Don’t slow down your app with emails or reports — queue them!
SendWelcomeEmail::dispatch($user);
Create the job:
php artisan make:job SendWelcomeEmail
Then run the queue worker:
php artisan queue:work
Users don’t have to wait — Laravel handles it in the background.
✅ Final Tips
- Always test your app after applying performance changes.
- Clear and rebuild your caches after any deployment.
- Use tools like Laravel Telescope, Debugbar, or Laravel Octane for deeper insights.
By applying even just 3–5 of these hacks, you’ll see noticeable improvements in load time, responsiveness, and scalability.
Keep it simple. Keep it clean. Keep it fast.
Ready to level up your Laravel app?