Memory usage increases linearly when (un)installing modules via config import

Created on 26 April 2023, over 1 year ago

Problem/Motivation

When importing config that has changes to core.extension (i.e enabling or uninstalling modules) memory usage grows linearly based on the number of modules being installed or uninstalled.

On our XL site:

  • When making 5 module changes (2 uninstalls, 3 installs) memory usage jumps to over 1GB.
  • The memory usage seems to be roughly the same if the combination is different (i.e 2 uninstalls and 1 install uses roughly the same memory as 1 uninstall and 2 installs).
  • 3 module changes peaks at ~800MB memory
  • 2 module changes peaks at ~700MB
  • 1 module change peaks at ~600MB

This was profiled using blackfire run php -d memory_limit=-1 ./bin/drush cim -y

Here's a screenshot of the Blackfire memory graph. Everything seems to stem from RouteBuilder::rebuild.

Things of note:
118,000 calls to unserialize
97,000 calls to serialize
45,000 SQL queries executed
When profiling a drush updb -y that does the following, memory usage peaked at 250MB

  $moduleInstaller = \Drupal::service('module_installer');
  $moduleInstaller->install([
    'module1',
    'module2',
    'module3',
  ], FALSE);
  $moduleInstaller->uninstall([
    'module4',
    'module5',
  ], FALSE);

Steps to reproduce

This is probably only applicable to large sites with a lot of routes/config/modules?

There does seem to be a somewhat linear memory usage just by doing the same thing with a standard profile and uninstalling some modules, although obviously MUCH lower memory (less than 200MB)

Proposed resolution

The main thing here is - why does memory usage keep increasing? RouteBuilder::rebuild is called once for every module change. Is there a memory leak in here somewhere?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

10.1 ✨

Component
ConfigurationΒ  β†’

Last updated about 24 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia acbramley

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024