[wp-hackers] [PATCH] Improve performance of convert_smilies by *10
Johan Eenfeldt
johan.eenfeldt at gmail.com
Mon Jan 5 19:55:24 GMT 2009
Hi,
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:
"/(\s|^)8(\)|-\)|-O|O)|\:(\!\:|\(|\)|-\(|-\)|-\?|-D|-P|-o|-x|-\||\?|\?\:|\?\?\?\:|D|P|arrow\:|cool\:|cry\:|eek\:|evil\:|grin\:|idea\:|lol\:|mad\:|mrgreen\:|neutral\:|o|oops\:|razz\:|roll\:|sad\:|shock\:|smile\:|twisted\:|wink\:|x|\|)|;(\)|-\))(\s|$)/e"
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
plugin.
Anyone wanting to test this without changing the code can try out the
plugin version included. It replaces the smilies_init action with the
new version.
Please consider this for inclusion.
Thank you,
Johan
[this mail might be duplicated as i somewhat messed up with
subscription/sending]
More information about the wp-hackers
mailing list