Module 4.6 – Analyze and Resolve Drupal Site Performance Issues

This module focuses on identifying and resolving Drupal site performance issues caused by configuration choices or custom code. Acquia exams evaluate whether you can analyze symptoms, understand Drupal internals, and select the most appropriate Drupal-aligned solution.

Performance questions are scenario-driven. Multiple options may technically work, but only one aligns with Drupal best practices, scales well, and preserves security.


1. Understanding Performance in Drupal

Performance in Drupal is about reducing repeated work. When Drupal rebuilds the same page, reruns the same query, or re-renders identical output for every request, performance degrades.

From a technical standpoint, Drupal performance depends on:

  • Effective use of caching layers
  • Efficient render pipeline
  • Optimized database access
  • Proper use of Drupal APIs
  • Clean separation of logic

Acquia exam principle:
If caching can solve the issue, that solution is preferred over code changes.


2. Common Causes of Performance Issues

Configuration-related causes

  • Page Cache disabled
  • Dynamic Page Cache disabled
  • Views caching turned off
  • Block caching disabled
  • CSS and JavaScript aggregation disabled

Custom code-related causes

  • Heavy logic inside hooks
  • Database queries inside loops
  • Missing cache metadata on render arrays
  • Bypassing render cache
  • Excessive static service calls

3. Drupal Caching Layers

Page Cache

Page Cache stores full HTML responses for anonymous users. When enabled, Drupal bypasses PHP execution for cached pages.

Typical symptom:
Anonymous users experience slow page loads.

Correct resolution:

  • Enable Page Cache
  • Avoid personalized output for anonymous pages

Acquia exam trap:
Modifying custom code is incorrect if Page Cache can resolve the issue.


Dynamic Page Cache

Dynamic Page Cache allows Drupal to cache pages for authenticated users while replacing only small dynamic sections.

Why it matters:

  • Improves performance for logged-in users
  • Prevents full page rebuilds on every request

Security note:
Dynamic Page Cache varies content by context, preventing data leakage.


Render Cache

Render Cache stores rendered elements such as blocks, views, and entities. It relies on cache metadata to determine reusability and invalidation.


4. Cache Metadata and Render Arrays

Correct implementation

return [
  '#markup' => $this->t('Example content'),
  '#cache' => [
    'max-age' => 3600,
    'contexts' => ['user.roles'],
    'tags' => ['node:1'],
  ],
];

Why this is correct:

  • Output is reusable
  • Cache invalidation works correctly
  • Rendering cost is reduced

Incorrect implementation

return [
  '#markup' => 'Example content',
];

Why this causes performance issues:

  • No cache metadata
  • Output is rebuilt every request

Acquia exam trap:
Missing cache metadata is often the root cause of performance problems.


5. Views Performance Issues

Common issues:

  • Views caching disabled
  • Large result sets
  • Too many selected fields
  • Missing database indexes

Correct optimization order:

  1. Enable Views caching
  2. Reduce selected fields
  3. Enable pagination
  4. Add database indexes
  5. Rewrite queries only when necessary

Acquia exam trap:
Jumping directly to custom SQL is almost always incorrect.


6. Database Query Efficiency in Custom Code

Inefficient pattern

foreach ($nids as $nid) {
  $node = Node::load($nid);
}

Why this is inefficient:

  • One database query per iteration
  • Poor scalability

Efficient pattern

$nodes = $this->entityTypeManager()
  ->getStorage('node')
  ->loadMultiple($nids);

Why this is correct:

  • Single query
  • Uses Entity API
  • Better performance characteristics

7. Hooks and Performance

Problematic usage

function example_module_node_view(array &$build) {
  // Expensive database operations
}

Why this is problematic:

  • Executes on every request
  • No inherent caching
  • Difficult to control performance impact

Correct approach:

  • Delegate logic to services
  • Execute conditionally
  • Attach cache metadata

Acquia exam rule:
Hooks should coordinate behavior, not perform computation.


8. Static Service Calls and Performance

Poor practice

\Drupal::entityTypeManager()->getStorage('node')->load($nid);

Why this hurts performance:

  • Repeated container lookups
  • Harder to test and reuse

Correct approach

public function __construct(EntityTypeManagerInterface $entity_type_manager) {
  $this->nodeStorage = $entity_type_manager->getStorage('node');
}

Why this improves performance:

  • Dependency reuse
  • Cleaner architecture
  • Easier caching and optimization

Acquia exam trap:
Static calls negatively impact scalability.


9. Frontend Assets and Performance

Configuration improvements:

  • Enable CSS aggregation
  • Enable JavaScript aggregation
  • Load libraries only when required

Example:

example_module.page:
  js:
    js/example.js: {}

Why this matters:
Each asset increases load time and processing overhead.


10. Logging and Performance

Excessive logging can significantly impact performance, especially inside loops or frequently executed code paths.

Correct usage:

  • Log only errors or critical events
  • Remove debug logging after troubleshooting

Acquia exam trap:
Logging itself can be the performance bottleneck.


11. Real-World Performance Scenarios

Scenario: Anonymous homepage is slow

Likely causes:

  • Page Cache disabled
  • Uncached blocks

Correct resolution:

  • Enable Page Cache
  • Add cache metadata to blocks

Scenario: Logged-in users experience slow navigation

Likely causes:

  • Dynamic Page Cache disabled
  • Views caching disabled

Correct resolution:

  • Enable Dynamic Page Cache
  • Enable Views caching

Scenario: Performance drops after deploying a custom module

Likely causes:

  • Database queries in hooks
  • Missing cache metadata

Correct resolution:

  • Move logic to services
  • Add cache tags and contexts

12. How Acquia Tests Performance Knowledge

Acquia evaluates your ability to:

  • Identify root causes
  • Prefer configuration over custom code
  • Apply Drupal-recommended solutions
  • Avoid premature optimization

Server-level tuning is out of scope for the exam.


Final Exam Revision Checklist

  • Page Cache enabled
  • Dynamic Page Cache enabled
  • Views caching enabled
  • Render arrays include cache metadata
  • No database queries inside loops
  • Hooks kept lightweight
  • Services used for business logic
  • Assets loaded only when needed

One-Sentence Takeaway

Drupal performance issues are best resolved through proper caching and correct architectural decisions.


Quick Mental Checklist for Exam Questions

Can this be cached
Is Drupal repeating work
Is configuration the solution
Is logic in the correct layer
Will this scale