Let's use token_scan() to see what tokens actually will be replaced and narrow the list returned from token_get_values() down to just those specific tokens. Should save on memory as well as processing since instead of 100+ tokens having to get 'cleaned' we only have to do it for the tokens that are actually in the pattern.

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new2.81 KB
dave reid’s picture

dave reid’s picture

Issue tags: +Performance
dave reid’s picture

Removing static caching in pathauto_cleanstring since that's a separate issue.

dave reid’s picture

Status: Needs review » Reviewed & tested by the community

Tested locally and it significantly reduces the amount of calls to pathauto_cleanstring() and all its related functions. This is fully-backwards-compatible if the user does not have a recent version of token.module with token_scan().

I even benchmarked this:

ab -n 50 http://mysql.drupal6dev.local/test.php

test.php:

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$result = db_query("SELECT nid FROM {node}");
$nids = array();
while ($nid = db_result($result)) {
  $nids[] = $nid;
}
pathauto_node_update_alias_multiple($nids, 'bulkupdate');
BEFORE PATCH
------------

Calls to pathauto_clean_string(): 23016
Requests per second:    0.18 [#/sec] (mean)
Time per request:       5701.199 [ms] (mean)
Time per request:       5701.199 [ms] (mean, across all concurrent requests)
Transfer rate:          0.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:  5437 5700 622.4   5598    8851
Waiting:     5436 5700 622.3   5598    8850
Total:       5437 5700 622.4   5598    8851


AFTER PATCH
-----------

Calls to pathauto_clean_string(): 505
Requests per second:    0.35 [#/sec] (mean)
Time per request:       2846.011 [ms] (mean)
Time per request:       2846.011 [ms] (mean, across all concurrent requests)
Transfer rate:          0.16 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:  2729 2845 118.6   2804    3255
Waiting:     2729 2845 118.6   2804    3255
Total:       2729 2845 118.6   2804    3255
dave reid’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 6.x-2.x only, as this will not apply to 6.x-1.x, and 7.x-1.x already uses the lazy-token generation in D7.
http://drupalcode.org/project/pathauto.git/commit/af21be3

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