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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sumanchalki created an issue. See original summary.

suman.abc’s picture

As 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.

suman.abc’s picture

Issue summary: View changes
suman.abc’s picture

Issue summary: View changes
suman.abc’s picture

Status: Active » Needs review
suman.abc’s picture

Category: Support request » Bug report

Version: 7.3 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.