I was noticing an extra array_shift() in the newly updated conf_init() function and I did a google search for performance differences and found this: http://webdevlogs.com/2007/05/11/array-shift-is-slower-than-i-thought

I will do a code search for other instances of array_shift() and provide a patch later.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

Title: array_shift($array) is much slower than $array[$i] » Remove array_shift wherever possible
Assigned: Unassigned » chx
Category: bug » task
Priority: Normal » Critical
Status: Active » Needs review
FileSize
16.19 KB

fixed cache problems with PostgreSQL and yet, MySQL performance suffers ever since. I removed array_shift and preg_replace_callback from db_query for mysql. Also removed from bootstrap and module inc -- the critical path (ie. the code ran to serve a cached page) now does not have array_shift.

chx’s picture

FileSize
16.21 KB

Let's try this version, which happens to work somewhat unlike the above :)

chx’s picture

Title: Remove array_shift wherever possible » [Performance] Remove array_shift wherever possible

Naturally, more patches will be needed to remove 'em all.

chx’s picture

Title: [Performance] Remove array_shift wherever possible » [Performance] Remove array_shift from the critical path
Category: task » bug
FileSize
2.62 KB

I can't load webdevlogs but the google cache of the original post still exists. I now simplified the patch to just removing array_shifts from bootstrap and module.

kevin francis’s picture

Tested chx's patch by creating several nodes of page and story types and it works without problems.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

RTBC

Gábor Hojtsy’s picture

It would be great to see that blog post before doing a commit on this.

chx’s picture

knock, knock. Is this thing on? Um. Anyone reads what I type? I doubt. Care to reread #4 ?

dvessel’s picture

tested, works here too.

Maybe a follow up patch is in order. theme() uses it and it's iterated quite often.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

OK, read up on the google cached text. Admittedly, it looks like we are better avoiding array_shift(), although I doubt much of this would show a difference in a benchmark. Nobody said he tried to benchmark.

Anyway, it saves us some cycles, and I don't think the code becomes any significantly unreadable, so committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)