Moshe found a linear slowdown when using devel generate to create terms in D7:

Attached patch does not fix this, I found the linear slowdown in devel_generate itself, see: #735706: Filesort in term generation.

However, while I was ruling things out, I did manage to find lots to optimize in taxonomy_term_save() itself.

Attached patch does the following:
1. Does not try to delete entries in taxonomy_term_hierarchy which cannot possibly exist.
2. Moves cache_clear_all() to the two submit handlers which update terms, there's no reason to clear the page cache when terms are inserted, or to have page cache clearing embedded in API functions - if I want to batch update a tonne of terms, I should be able to run cache_clear_all() at the end, or leave the stale cache entries for a few minutes even.
3. Removes a bogus check for is_array($term->parent) immediately after we've guaranteed it's an array.
This improves taxonomy_term_save() performance as measured by devel generate from up from 1,300 terms/minute on my laptop to approximated 2100 terms/minute.

Before patch:

catch@catch-laptop:~/www/7$ drush generate-taxonomy 1 20000 --feedback=1000 -d
Completed 1000 terms (1304 terms/min) [50.97 sec, 31.39 MB]                                                                                                                                         [ok]
Completed 1000 terms (1224 terms/min) [99.73 sec, 31.39 MB]                                                                                                                                         [ok]
Completed 1000 terms (1277 terms/min) [146.7 sec, 31.39 MB] 

After patch:

catch@catch-laptop:~/www/7$ drush generate-taxonomy 1 20000 --feedback=1000 -d
Completed 1000 terms (2069 terms/min) [34.26 sec, 31.38 MB]                                                                                                                                         [ok]
Completed 1000 terms (2069 terms/min) [63.42 sec, 31.38 MB]                                                                                                                                         [ok]
Completed 1000 terms (2069 terms/min) [92.37 sec, 31.39 MB]                                                                                                                                         [ok]
Completed 1000 terms (2069 terms/min) [121.5 sec, 31.39 MB]                                                                                                                                         [ok]
Completed 1000 terms (2000 terms/min) [150.98 sec, 31.39 MB]  

Have not run tests on this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

Forgot patch :(

Status: Needs review » Needs work
Issue tags: -Performance

The last submitted patch, taxonomy_term_save_a_bit_faster.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
Issue tags: +Performance

#1: taxonomy_term_save_a_bit_faster.patch queued for re-testing.

..Somehow I don't think this is causing mail and javascript system test to fail.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Looks like a nice cleanup, and bot is green

catch’s picture

Issue tags: -Performance

Status: Reviewed & tested by the community » Needs work
Issue tags: +Performance

The last submitted patch, taxonomy_term_save_a_bit_faster.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
FileSize
3.4 KB

Other cleanups went in, re-roll. This now only deals with the cache_clear_all() and the is_array().

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

code looks good. please wait for green before commit

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Performance

Automatically closed -- issue fixed for 2 weeks with no activity.