Performance
In order to ensure that FilamentFlow is as fast and efficient as possible, we have implemented a number of performance optimizations. These optimizations are designed to reduce the amount of time it takes to load pages, process requests, and perform other tasks within the application.
The number one performance implication we see ignored in Laravel applications is a failure to eager load relationships. This is a common mistake that can have a significant impact on the performance of your application. When you fail to eager load relationships, your application will make a separate query for each relationship, which can result in a large number of queries being executed. This can slow down your application and make it less responsive.
The AppServiceProvider.php
includes the following in the boot method:
// Prevent lazy loading in local development environments
Model::preventLazyLoading( config( 'app.debug' ) );
This will prevent lazy loading in local development environments, which can help you identify and fix any issues related to eager loading so that you can optimize the performance of your application prior to deployment.
How do I know if I need to eager load relationships?
If you see a message similar to the following image, you need to eager load relationships:
How do I eager load relationships?
To eager load relationships, you can use the with
method on your query. For example:
public static function table(Table $table): Table
{
return $table
->query(function (): Builder {
return User::query()
->withoutGlobalScopes()
->with( 'roles' );
})
...
This will eager load the roles
relationship for each user in the query, which will help to reduce the number of queries that are executed when the page is loaded.
See the Laravel documentation for more information on eager loading relationships in Laravel.