Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For large number of taxonomy terms, the term edit page is taking considerable memory and time. For an example scenario, a term has total 10899 child items and vocabulary item has 48984 items it is taking 140 seconds and 238MB of memory in my local computer.
The issue is caused by the horrible performance of in_array() function at line number 730 of taxonomy/taxonomy.admin.inc (if (!in_array($item->tid, $exclude)) {
).
// A term can't be the child of itself, nor of its children.
foreach ($children as $child) {
$exclude[] = $child->tid;
}
$exclude[] = $term->tid;
$tree = taxonomy_get_tree($vocabulary->vid);
$options = array('<' . t('root') . '>');
if (empty($parent)) {
$parent = array(0);
}
foreach ($tree as $item) {
if (!in_array($item->tid, $exclude)) {
$options[$item->tid] = str_repeat('-', $item->depth) . $item->name;
}
}
If the code logic can be modified there can be significant improvement.
Comment | File | Size | Author |
---|---|---|---|
#2 | taxonomy-long_time_memory-2877986-1.patch | 1.61 KB | suman.abc |
Comments
Comment #2
suman.abc CreditAttribution: suman.abc commentedAs mentioned in the issue in_array() function is performing bad, we can modify the logic. The attached patch improves scenario for my case: time taken 6 seconds whereas memory consumption does not improve.
Comment #3
suman.abc CreditAttribution: suman.abc commentedComment #4
suman.abc CreditAttribution: suman.abc commentedComment #5
suman.abc CreditAttribution: suman.abc commentedComment #6
suman.abc CreditAttribution: suman.abc commented