This piece fo code in registry.inc is terribly inefficient calling array_keys for (the relatively large array) $files in every loop iteration.

foreach ($lookup_cache as $key => $file) {
  // If the file for this cached resource is carried over unchanged from
  // the last registry build, then we can safely re-cache it.
  if ($file && in_array($file, array_keys($files)) && !in_array($file, $parsed_files)) {
    $unchanged_resources[$key] = $file; 
  }
}

On my machine it takes abount 20 miliseconds to run this loop. Using array_key_exists instead cuts the execution time to 0.1 miliseconds, making it two orders of magnitude faster.

foreach ($lookup_cache as $key => $file) {
  // If the file for this cached resource is carried over unchanged from
  // the last registry build, then we can safely re-cache it.
  if ($file && array_key_exists($file, $files) && !in_array($file, $parsed_files)) {
    $unchanged_resources[$key] = $file; 
  }
}

I know this is nitpicking as this code is not run very often, but such it's such a small, 100% safe, change (with a marginally positive effect on performance) i still think it could be worth committing.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gnucifer’s picture

gnucifer’s picture

Issue summary: View changes
gnucifer’s picture

Issue summary: View changes
mgifford’s picture

Assigned: gnucifer » Unassigned

Does this apply to Drupal 8 as well? If so it needs to be fixed there first.

joelpittet’s picture

Issue tags: +Performance
FileSize
626 bytes

isset() is a bit more of a micro-optimization, how about this?

@mgifford, the registry exists in D8 but this pattern could be fixed in a number of other places in D8 and D7. Anybody interested in opening up issues for these I'll gladly RTBC:
Regex search:in_array\(\$[^,]+, array_key

sjerdo’s picture

Status: Needs review » Reviewed & tested by the community

patch #5 LGTM +1

joseph.olstad’s picture

+1 , feel that need for speed.

joelpittet’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
joseph.olstad’s picture

Yay, faster and faster! Keep up the great work Joelpittet