Skip to content

Instantly share code, notes, and snippets.

@jbergstroem
Created June 9, 2010 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbergstroem/432135 to your computer and use it in GitHub Desktop.
Save jbergstroem/432135 to your computer and use it in GitHub Desktop.

Drupal 7 runtime optimizations

Here's a couple of ideas for increasing Drupal runtime speeds I picked up while digging trough the code.

array_key_exists -> isset

replace array_key_exists($name,$array) with isset($array[$key]);

Isset is about 2.5 times faster. One thing to notice is that behavior isn't identical:

$array['key'] = NULL;
var_dump(isset($array['key'])); // false
var_dump(array_key_exists('key', $array)); // true

This will have no change in drupal; drupal_static has about 300 calls on a "minimal setup" (on an authenticated front page refresh), and checks a key before setting it. I couldn't find any key set to null while checking with xdebugs.collect_params

Make Drupal serializer configurable

Serialize/unserialize has gotten a couple of contenders. These are considerably faster. Since serialize/unserialize have hundreds of calls per pageview on a normal Drupal site, this will make a noticeable impact. Here's a [benchmark_framework] that compares a couple of serializers currently available.

Only fetch get_defined_constants once

drupal_parse_info_format fetches defined constants on each instantiation which is painfully slow (and memory hungry). This should be stored on first get and only be accessed from the local scope.

I haven't read enough code do decide if this define chain is manipulated between reads, so that would also have to be verified before storing.

redirect to image instead of reading buffers

NOTE: WIP - see http://drupal.org/node/805416 The image.module (and perhaps in other places) processes images ineffectively since they first process it, store the image and then reads the buffer and returns an image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment