Improve the performance of db_prefix_tables when many prefixes are used #24

wants to merge 1 commit into


None yet
2 participants

Here is the issue, and this patch:

The running time of the function db_prefix_tables() grows linearly as the number of prefixes in $db_prefix array increases. Our client has 151 entries in this array, and thus we are seeing a significant amount of time spent prefixing table names in SQL strings. On page requests with many queries, this could be 50% of the page load time, as the db_prefix_tables function is poorly optimized for large arrays of prefixes.

The patch uses preg_replace_callback to achieve the same thing, and uses the default Drupal behavior in cases where there is 1 or 0 db_prefixes, which is the safest way to go about this.

Hoping this gets committed to Drupal 6, however client would like to upgrade to Pressflow so proposing this patch.


elliotttf commented Feb 13, 2012

Haven't tested the code change but it looks good to me and I agree with Mark's defense of this approach here:

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