for quite big $db_prefix arrays db prefixing can take some time and so decrease performance.

e.g. i 've tested an $db_prefix arrray with ~25entries, which lead to about 20ms more page generation time on /admin (200ms instead of 180).

the attached patch changes db_prefix_tables() to use preg_replace, which seems to be a bit faster (got 193ms instead of 200ms).
further this patch changes matching, so that e.g. profile would match to {profile_fields} and {profile_values}. this allows reducing the size of $db_prefix substantially, think of e.g. the flexinode tables. it's possible to avoid this match by appending a '}', e.g. using 'users}' would match only to 'users' and not to 'users_roles'

so in my use case, i was able to reduce the /admin page generation time to 185ms with an equal prefixing.

Comments

dries’s picture

Status: Needs review » Needs work

Looks cool but coding style needs work. It's also a good idea to document the new features.

fago’s picture

StatusFileSize
new2.81 KB

i've attached an updated patch.

it includes some documentation in the default settings.php file.

fago’s picture

Status: Needs work » Needs review
killes@www.drop.org’s picture

I am wondering whether we could make $search and $replace static variables so we only need to compute them once per page view.

fago’s picture

good idea, i'll try it

fago’s picture

StatusFileSize
new2.9 KB

this seems to be another fine improvement.

now, i get only 182-183ms on /admin for my test case.

drumm’s picture

Category: task » feature
coreb’s picture

Version: x.y.z » 6.x-dev

(Moving x.y.z version to a real version number) Feature Request => 6.x-dev

webchick’s picture

Status: Needs review » Needs work

Does not apply.

pancho’s picture

Version: 6.x-dev » 7.x-dev

Need to move this to the D7 queue.

tisho-1’s picture

This patch has been a lifesaver for me. With 160 shared tables I saw a *** 1 second *** overhead! After applying the patch this overhead is gone.

You can see more information on the problem in this thread: http://groups.drupal.org/node/18369

I hope this makes it at least into 7.x!

Thank you!

catch’s picture

Category: feature » task

Changing to task and subscribing.

mrfelton’s picture

This patch is a must if you're using civicrm which required that you db_prefix over 125 tables to get views integration.

mrfelton’s picture

Issue tags: +Performance

Adding 'Performance' tag.

mrfelton’s picture

StatusFileSize
new2.58 KB
new97.36 KB
new99 KB

I just benchmarked the db_prefix_tables() this using xdebug and webgrind with a setup using 125 prefixed tables (due to civicrm)

BEFORE
Invocation count: 457ms
Total self cost: 961ms
Total inclusive cost: 1339ms

AFTER
Invocation count: 456ms
Total self cost: 40ms
Total inclusive cost: 79ms

The db_prefix_tables() function went from being THE most expensive function that took up almost 20% of processing time, down, to the 25th most expensive function taking up less than 2% of the total time.

See attached screenshots

Also attached is an updated version of the patch that was created against Druapl 6.14

catch’s picture

Priority: Normal » Critical

db_prefix_tables() doesn't exist in D7. I'm not sure if the D7 implementation suffers from any of the same issues, but that's being refactored over at #302327: Support cross-schema/database prefixing like we claim to.

So I'm moving this back to D6. Also bumping to critical since 1/5 of request time is massive.

mrfelton - could you post benchmarks?

catch’s picture

Version: 7.x-dev » 6.x-dev
mrfelton’s picture

@catch: What kind of benchmarks do you want to see? Do the screenshots above not show enough?

catch’s picture

My bad, I completely ignored the screenshots :(

mrfelton’s picture

any movement here - would sure be great to see this fixed in core. The performance hit incurred here is seriously large.

jonne_jvl’s picture

Status: Needs work » Needs review

Tried it on a 6.17 multisite setup.
Works fine, similar speedup as reported in #1 of around ~20ms

I dont read regex, sorry.

Status: Needs review » Needs work

The last submitted patch, 42827-db-prefix-performance-v2.patch, failed testing.

dpearcefl’s picture

Status: Needs work » Postponed (maintainer needs more info)

If this is still needed, please submit the patch with fixes.

dpearcefl’s picture

Status: Postponed (maintainer needs more info) » Needs work
lyricnz’s picture

The strtr/str_replace issue was recently fixed in D7/D8 over on #561422: Replace strtr() with str_replace() for db prefixing. I think that solution removes the need to change the meaning of the tablenames in $db_prefix? If others agree, suggest closing this as duplicate (of the "needs backport" over there).

andypost’s picture

Status: Needs work » Closed (duplicate)