[wp-hackers] [PATCH] Improve performance of convert_smilies by *10
johan.eenfeldt at gmail.com
Mon Jan 5 19:55:24 GMT 2009
When profiling filter performance I found that the single most
expensive one was convert_smilies (can be 30+% of total page
construction time on post with many comments).
This patch changes smilies_init to make a more efficient regular
expression resulting in a *10 speedup.
This is done by:
o the search expression is built up as sub-expressions for smiley
first letter (example of partial result: "8(\)|-\)|-O|O)").
o to handle the replacement it uses the 'e' modifier at end of search
string which makes preg_replace() treat the replacement parameter as
PHP code after reference substitution is done.
Resulting generated search regular expression for default smilies:
Of possible note: the $wp_smiliessearch and $wp_smiliesreplace globals
are now plain strings and not arrays.
This makes no difference for any other core code, or any outside uses
if used in the recommended way but could perhaps possibly confuse some
Anyone wanting to test this without changing the code can try out the
plugin version included. It replaces the smilies_init action with the
Please consider this for inclusion.
[this mail might be duplicated as i somewhat messed up with
More information about the wp-hackers