[wp-hackers] [PATCH] Improve performance of convert_smilies by *10

Johan Eenfeldt johan.eenfeldt at gmail.com
Mon Jan 5 21:16:07 GMT 2009


On Mon, Jan 5, 2009 at 9:06 PM, mrmist <listswphackers at mist.org.uk> wrote:
> In message <7547287e0901051155x754dcf7dub9cd193f553aa3ee at mail.gmail.com>,
> Johan Eenfeldt <johan.eenfeldt at gmail.com> writes
>>
>> 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.
>>
> Nice idea, but see http://trac.wordpress.org/ticket/8689
> --
> mrmist

Ok, so I rewrote it using preg_replace_callback(), as suggested by
sewpafly as well as the ticket. Patch attached.

Some more numbers. Load time on the site for a post with 403 comments:
Original: 4.3s
Modified: 2.6s

The move to the preg_replace_callback() did not seem to make any big
difference in performance.

(as this required changes in convert_smilies() it is not possible to
make it with the plugin architecture)

/ Johan


More information about the wp-hackers mailing list