Problem/Motivation
When a taxonomy vocabulary contains too many terms, it is absolutely impossible to reach some pages like taxonomy overview, even if their content is paginated, because of huge memory usage.
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/web/core/lib/Drupal/Core/Cache/DatabaseBackend.php on line 167
This is caused by the taxonomy_get_tree function for huge taxonomies, but for medium sized taxonomies, this is also caused by the fact that we never clean unused variables.
For information, with a 72000 terms taxonomy (what is not so many for big websites) :
$start = memory_get_usage(TRUE);
$tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vid); // 72000 terms
$used_memory = memory_get_usage(TRUE) - $start;
echo $used_memory; // ~ 242 MB
Proposed resolution
Unset loadTree result when it is not needed anymore. This will not save the life of huge websites, but this will definetely help medium ones to stay usables.
Refactor the implementation to use less memory in general and especially with pagination.
Remaining tasks
Post the patch
User interface changes
None
API changes
None
Beta phase evaluation
-->
Issue category | Bug because it can cause fatal errors on very common features |
---|---|
Issue priority | Major because that's a bug |
Prioritized changes | The main goal of this issue is performance. (By clearing that unused variables we can free up a lot of memory) |
Disruption | Not disruptive for core, contributed and custom modules because the variables are cleared while neither the core or a hook uses them. |