Here is the Drupal.org issue, and this patch: http://drupal.org/node/561422#comment-5592350
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.
Commit of patch from http://drupal.org/node/561422#comment-5592350
Haven't tested the code change but it looks good to me and I agree with Mark's defense of this approach here: http://drupal.org/node/561422#comment-5595204