Drupal Performance Issues
Platform-specific guides for diagnosing and fixing Core Web Vitals and performance issues on Drupal.
Core Web Vitals
Largest Contentful Paint (LCP)
Fix slow main content loading on Drupal. Target: under 2.5 seconds.
Cumulative Layout Shift (CLS)
Resolve visual stability issues causing layout shifts. Target: under 0.1.
Common Drupal Performance Issues
Database Performance
Drupal's database-driven architecture can create performance bottlenecks if not properly optimized.
Common issues:
- Inefficient queries from contrib modules
- Missing database indexes
- Large database tables (watchdog, cache_* tables)
- Excessive database connections
- Unoptimized Views queries
Optimization strategies:
- Enable query logging to identify slow queries
- Add indexes to frequently queried fields
- Regularly truncate watchdog and cache tables
- Use Redis or Memcached for database query caching
- Optimize Views with proper filters and caching
- Use the Devel module's query log during development
Drupal configuration:
// settings.php
$settings['database_cache_max_rows'] = ['default' => 5000];
Caching Strategies
Drupal's multi-layered caching system is critical for performance.
Page caching:
- Enable Drupal's internal page cache for anonymous users
- Set appropriate cache lifetimes (600-3600 seconds recommended)
- Use Smart Cache or Cache Tags for granular invalidation
- Implement BigPipe for progressive page rendering (Drupal 8+)
Dynamic page cache (Drupal 8+):
// Enable for authenticated users
$config['system.performance']['cache']['page']['max_age'] = 3600;
Block caching:
- Configure per-block cache settings
- Use cache contexts and tags appropriately
- Cache menu blocks separately from content blocks
Views caching:
- Enable time-based or tag-based caching for Views
- Cache Views results and rendered output separately
- Use "Search API" for complex listing pages
External caching layers:
- Implement Varnish for reverse proxy caching
- Use Redis or Memcached for backend caching
- Configure CloudFlare or Fastly for edge caching
Drupal cache configuration:
// settings.php - Redis configuration
$settings['redis.connection']['interface'] = 'PhpRedis';
$settings['redis.connection']['host'] = '127.0.0.1';
$settings['redis.connection']['port'] = 6379;
$settings['cache']['default'] = 'cache.backend.redis';
Theme and Template Optimization
Common problems:
- Excessive Twig template processing
- Unoptimized theme hooks and preprocess functions
- Too many regions loading on every page
- Heavy base themes (Bootstrap, Foundation)
Solutions:
- Disable Twig debugging in production
- Use Twig template caching
- Minimize preprocessing logic
- Remove unused theme regions
- Use lightweight base themes or custom themes
- Aggregate and minify CSS/JS files
Twig optimization:
// settings.php - Disable Twig debugging
$settings['twig_debug'] = FALSE;
$settings['twig_cache'] = TRUE;
$settings['twig_auto_reload'] = FALSE;
Module Performance
Contributed modules can significantly impact Drupal performance.
Performance-heavy modules to watch:
- Views (especially with complex relationships)
- Panels/Page Manager (excessive layout processing)
- Token module (recursive token replacement)
- Webform (complex form processing)
- Search API (indexing overhead)
Best practices:
- Audit enabled modules quarterly
- Disable unused modules completely (don't just uninstall)
- Use lightweight alternatives when possible
- Monitor module query counts with Devel
- Update modules regularly for performance patches
- Use Drush commands for module management
Check module overhead:
drush php-eval "print_r(module_list());"
Image Optimization
Drupal-specific image handling:
- Use Image Styles for automatic resizing and caching
- Enable lazy loading module for below-fold images
- Configure WebP image format with fallbacks
- Use responsive image module for srcset generation
- Set appropriate image quality in Image Style settings (80-85% recommended)
Image Style configuration:
// Example: Optimize image quality
$config['image.style.large']['effects']['image_scale']['data']['quality'] = 85;
Recommended modules:
- ImageAPI Optimize - Automated image compression
- Lazy Load - Defer offscreen images
- Responsive Images - Automatic srcset generation
- WebP - Modern image format support
JavaScript and CSS Aggregation
Drupal's asset management:
- Enable CSS and JS aggregation in performance settings
- Use Advanced CSS/JS Aggregation module for better optimization
- Implement critical CSS for above-the-fold content
- Defer non-critical JavaScript loading
- Remove unused libraries from pages
Configuration:
// Enable aggregation
$config['system.performance']['css']['preprocess'] = TRUE;
$config['system.performance']['js']['preprocess'] = TRUE;
Advanced aggregation settings:
- Enable GZIP compression
- Combine multiple CSS/JS files
- Minify aggregated assets
- Implement async/defer attributes
Drupal-Specific Performance Modules
Essential Performance Modules
Drupal 7:
- Boost - Static page caching for maximum performance
- Varnish - Reverse proxy integration
- Memcache API and Integration - Memory-based caching
- Advanced CSS/JS Aggregation - Better asset optimization
- ImageAPI Optimize - Automatic image compression
Drupal 8/9/10:
- Advanced CSS/JS Aggregation - Enhanced asset bundling
- Redis - High-performance caching backend
- Varnish Purge - Automated cache invalidation
- Lazy Load - Image lazy loading
- Fast 404 - Optimize 404 error handling
Performance Monitoring Modules
- Devel - Query and performance debugging
- Webprofiler - Detailed performance profiling
- New Relic APM - Application performance monitoring
- Performance Profiler - Track page generation times
Platform-Specific Troubleshooting
Slow Admin Pages
Admin pages in Drupal often perform poorly due to heavy processing.
Causes:
- Complex administrative Views
- Module configuration forms with heavy processing
- Node edit forms with many fields
- Media library browsing
Fixes:
- Use Admin Toolbar module for streamlined navigation
- Optimize administrative Views with proper caching
- Implement field groups to reduce field loading
- Use Media Library optimizations for large media collections
Slow Content Listing Pages
Optimization strategies:
- Use Views with appropriate caching settings
- Implement pager limits (25-50 items recommended)
- Add database indexes to sorted/filtered fields
- Use Search API instead of Views for large datasets
- Cache Views results and rendered output separately
Entity Query Performance
Best practices:
- Use EntityQuery for better performance over direct database queries
- Implement proper access checks to leverage caching
- Add database indexes for frequently queried fields
- Use Query Tags for query alteration hooks
- Limit query results with range() method
Form Performance
Heavy forms can slow down Drupal significantly.
Optimization techniques:
- Reduce number of fields loaded simultaneously
- Use field groups with collapsible fieldsets
- Implement AJAX for dependent fields instead of full reloads
- Disable autocomplete for large datasets
- Use Select2 or Chosen modules for better select performance
Drupal Hosting and Infrastructure
Recommended Server Configuration
PHP optimization:
; php.ini recommendations
memory_limit = 256M
max_execution_time = 60
upload_max_filesize = 64M
post_max_size = 64M
opcache.enable = 1
opcache.memory_consumption = 256
opcache.max_accelerated_files = 10000
Database optimization (MySQL/MariaDB):
; my.cnf recommendations
innodb_buffer_pool_size = 2G
innodb_log_file_size = 512M
query_cache_size = 64M
query_cache_type = 1
Content Delivery Network (CDN)
CDN integration:
- Use CDN module for automatic asset URL rewriting
- Configure CloudFlare, Fastly, or Akamai
- Serve static assets from CDN
- Implement proper cache headers
- Use CDN for file downloads and media
CDN module configuration:
// settings.php
$config['cdn.settings']['status'] = TRUE;
$config['cdn.settings']['cdn_domain'] = 'cdn.example.com';
Drupal-Specific Performance Testing
Drush commands for performance:
# Clear all caches
drush cr
# Rebuild cache
drush cache-rebuild
# Check system status
drush status
# Run cron for cache maintenance
drush cron
# Analyze Views performance
drush views-analyze
Performance profiling:
- Use XHProf or Blackfire.io for PHP profiling
- Enable Webprofiler for detailed performance data
- Monitor with New Relic or AppDynamics
- Use MySQL slow query log
Diagnostic Tools
- Google PageSpeed Insights - Core Web Vitals analysis
- Chrome DevTools Performance Tab - Detailed waterfall analysis
- Lighthouse - Comprehensive performance audit
- Drupal Devel Module - Query and performance debugging
- Webprofiler - Request profiling and optimization suggestions
- Drush - Command-line diagnostics and cache management
Key Metrics for Drupal
Performance targets:
- Time to First Byte (TTFB): Under 200ms
- First Contentful Paint (FCP): Under 1.8s
- Largest Contentful Paint (LCP): Under 2.5s
- Database queries per page: Under 100 (ideally under 50)
- Cache hit ratio: Above 90%
Advanced Performance Techniques
Implement Varnish Caching
Varnish provides powerful reverse proxy caching for Drupal.
VCL configuration for Drupal:
# Remove cookies for static assets
if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|js|svg|woff)$") {
unset req.http.cookie;
}
# Cache purging for Drupal
if (req.method == "PURGE") {
return (purge);
}
Database Replication
For high-traffic sites, implement database replication:
- Master database for writes
- Slave databases for reads
- Configure in settings.php
$databases['default']['slave'][] = [
'database' => 'drupal',
'username' => 'drupal_slave',
'password' => 'password',
'host' => 'slave-db-server',
'driver' => 'mysql',
];
Implement BigPipe (Drupal 8+)
BigPipe allows progressive page rendering for faster perceived performance.
// Enable BigPipe module
drush en bigpipe -y
Optimize Cron Operations
Heavy cron tasks can impact site performance.
Best practices:
- Run cron externally via Drush or cURL
- Schedule resource-intensive operations during off-peak hours
- Split heavy operations into smaller batches
- Monitor cron execution time
# External cron via Drush
*/15 * * * * cd /path/to/drupal && drush cron
Ongoing Maintenance
Regular Performance Audits
Monthly tasks:
- Review slow query log
- Check database table sizes
- Audit enabled modules
- Test page load times across site sections
- Monitor Core Web Vitals in Google Search Console
- Review cache hit ratios
Update Strategy
- Keep Drupal core updated for performance improvements
- Update contributed modules regularly
- Test updates in staging environment first
- Monitor Drupal.org security advisories
- Use Composer for dependency management (Drupal 8+)
General Fixes
For universal performance concepts, see the Global Performance Issues Hub.