Laravel Performance Wins That Take Less Than 10 Minutes
One of the biggest misconceptions about performance is that it requires massive refactoring, new infrastructure, or complicated caching layers.
In reality, many performance improvements come from small adjustments to everyday code.
Over the years working on production Laravel systems, I've noticed the same simple fixes appear again and again. These changes are often overlooked, yet they can reduce database load, improve response time, and make your application feel dramatically faster.
Here are some of the easiest performance wins you can implement in under ten minutes.
1. Fix N+1 Queries with Eager Loading
One of the most common Laravel performance issues is the N+1 query problem.
Example:
$posts = Post::all();
foreach ($posts as $post) {
echo $post->author->name;
}
This may execute one query for posts and another query for each author.
Instead, eager load the relationship.
$posts = Post::with('author')->get();
Now Laravel loads everything in two queries instead of dozens or hundreds.
This is often the single biggest performance improvement in many applications.
2. Only Select the Columns You Need
By default, Laravel retrieves all columns from a table.
$users = User::all();
But if you only need a few fields, select them explicitly.
$users = User::select('id', 'name')->get();
This reduces:
- memory usage
- network transfer
- query time
It also becomes especially valuable when working with large tables.
3. Use exists() Instead of count()
A common pattern looks like this:
if (User::where('email', $email)->count() > 0) {
// user exists
}
But count() forces the database to count every matching row.
Instead:
if (User::where('email', $email)->exists()) {
// user exists
}
exists() stops searching as soon as the first record is found, making it much faster.
4. Cache Expensive Queries
If a query result rarely changes, cache it.
$plans = Cache::remember('plans', 3600, function () {
return Plan::all();
});
This reduces database load and can dramatically speed up repeated requests.
Laravel makes caching extremely simple, and many queries benefit from it immediately.
5. Use Route Caching
Laravel must parse your route files on every request unless they are cached.
You can cache routes with a single command:
php artisan route:cache
This converts your routes into a compiled file that loads much faster.
For production environments, this should almost always be enabled.
6. Cache Your Config
Configuration files also get loaded and parsed on every request.
Laravel provides a simple optimization:
php artisan config:cache
This creates a single cached config file and improves application boot time.
Most production deployments include this step.
7. Avoid env() Calls Outside Config
Calling env() repeatedly in application code slows things down because Laravel reads environment variables each time.
Instead of doing this in your code:
$apiKey = env('SERVICE_API_KEY');
Move it into a config file:
'api_key' => env('SERVICE_API_KEY'),
Then access it with:
config('services.api_key');
This plays nicely with Laravel's config caching and improves performance.
8. Use chunk() for Large Datasets
Loading thousands of rows into memory can slow down your app and increase memory usage.
Instead of:
$users = User::all();
Use chunking:
User::chunk(100, function ($users) {
foreach ($users as $user) {
// process user
}
});
Laravel will process records in small batches, preventing memory issues.
9. Queue Slow Tasks
Anything slow should rarely happen during a web request.
Examples include:
- sending emails
- generating reports
- processing images
- calling external APIs
Laravel makes it easy to move these into the queue:
SendWelcomeEmail::dispatch($user);
The request returns immediately while the job runs in the background.
Users experience much faster page loads.
10. Use Lazy Collections for Streaming Data
If you're working with very large datasets, lazy collections can help.
User::cursor()->each(function ($user) {
// process user
});
This streams records from the database instead of loading everything into memory.
It is perfect for:
- data exports
- batch processing
- background jobs
Final Thoughts
Performance tuning doesn't always require complex architecture or expensive infrastructure.
Often the best improvements come from small habits applied consistently.
A few eager loads, a bit of caching, and avoiding unnecessary queries can dramatically improve how your application performs in production.
The best part is that many of these changes take less time to implement than it took to read this article.
When working on Laravel systems, I regularly look for these small opportunities first. They are quick, safe, and often produce immediate results.
If you enjoyed this article, you may also like:
- SOLID in Laravel: What It Actually Looks Like in Real Code
- Why PSR‑12 Still Matters (and When It Doesn't)
- How I Structure a Laravel App That's Meant to Grow
Member discussion