Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 300851

Improve installer performance by ~20% by rebuilding the router after the entire installation is complete rather than after each module

$
0
0

Drupal rebuilds the router on each module installation. This is useful when adding modules once Drupal has been installed.

However, it is causing a lot of CPU cycles when Drupal is installing and the routes may be rebuilt over and over. Here's a screenshot from a Blackfire profile shaal created while we were debugging the Umami demo's installation time. The router is rebuilt 55 times before Drupal has finished being installed.

Here is the current code:

      if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
        // Rebuild routes after installing module. This is done here on top of
        // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
        // fastCGI which executes ::destruct() after the module installation
        // page was sent already.
        \Drupal::service('router.builder')->rebuild();
      }

Adding a check to drupal_installation_attempted () greatly improves the installation time. Here is the comparison when we check if Drupal is installed first

      if (!drupal_installation_attempted() && !\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
        // Rebuild routes after installing module. This is done here on top of
        // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
        // fastCGI which executes ::destruct() after the module installation
        // page was sent already.
        \Drupal::service('router.builder')->rebuild();
      }

Viewing all articles
Browse latest Browse all 300851

Trending Articles