Introduction
Filament applications can handle large datasets and complex UIs efficiently when properly optimized. This guide covers various techniques to improve performance at the database, application, and frontend levels.Database optimization
Eager loading relationships
Prevent N+1 query problems by eager loading relationships in your resources:Counting relationships efficiently
UsewithCount() instead of loading full relationships when you only need counts:
Selective column loading
Load only the columns you need:Database indexing
Add indexes to frequently queried and sorted columns:Query optimization for filters
Optimize filter queries:Table performance
Deferring table loading
Defer table rendering to improve initial page load:Pagination optimization
Use appropriate pagination settings:Lazy loading columns
Lazy load expensive column calculations:Disable unnecessary features
Disable features you don’t need:Caching strategies
Caching select options
Cache expensive select option queries:Caching dashboard widgets
Cache widget data for dashboards:Invalidating caches
Invalidate caches when data changes:Asset optimization
Preloading relationships in forms
Preload select options to reduce queries:getOptionLabelFromRecordUsing() to avoid extra queries:
Optimizing file uploads
Optimize image uploads with automatic resizing:Livewire optimization
Reducing Livewire updates
Uselazy() for heavy calculations:
Polling optimization
Optimize polling intervals:Offline support
Handle offline states gracefully:Query optimization
Using chunking for bulk operations
Process large datasets in chunks:Lazy collections for memory efficiency
Use lazy collections for large datasets:Optimizing search queries
Use full-text search for better performance:Advanced techniques
Using queue workers
Offload heavy operations to queues:Database connection optimization
Use read/write connections:Horizon for queue monitoring
Monitor queue performance with Laravel Horizon:Using Redis for caching
Configure Redis for better cache performance:Monitoring performance
Using Laravel Telescope
Monitor application performance:Query logging
Log slow queries for optimization:Performance profiling
Use Clockwork for profiling:Best practices
- Always eager load relationships to prevent N+1 queries
- Use database indexing on frequently queried columns
- Cache expensive operations and calculations
- Use pagination for large datasets
- Implement lazy loading for heavy columns
- Use
withCount()instead of loading full relationships - Optimize file uploads with compression and resizing
- Use queues for long-running operations
- Monitor slow queries and optimize them
- Use Redis for caching in production
- Implement full-text search for large text searches
- Use
select()to load only needed columns - Process bulk operations in chunks
- Use lazy collections for memory efficiency
- Defer table loading when appropriate
- Minimize Livewire polling intervals
- Use database transactions for consistency
- Profile your application regularly
Performance checklist
- Database indexes added for sortable and searchable columns
- Relationships eager loaded in
getEloquentQuery() - Using
withCount()for relationship counts - Select options cached where appropriate
- Dashboard widgets cached with appropriate TTL
- File uploads optimized with resizing and format conversion
- Pagination configured appropriately
- Heavy operations moved to queues
- Redis configured for caching
- Slow query logging enabled
- Full-text search implemented for large text fields
- Table loading deferred when appropriate
- Livewire polling optimized
- Telescope or Clockwork installed for monitoring
- Database read/write replicas configured (if applicable)