#6464 closed defect (bug) (fixed)
convert_smilies is very slow
Reported by: | Acci | Owned by: | |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Optimization | Keywords: | has-patch, tested |
Focuses: | Cc: |
Description
I created a testing WordPress blog with 10 posts and I found huge performance problem in convert_smilies
function. This function took at average 39 ms on my high-end PC.
Currently this function uses preg_replace
and it's called 40× for each part of the post.
My solution is to use very similar function preg_replace_callback
with modified regular expression. This solution is 6× faster than original (5,9 ms).
Attachments (5)
Change History (14)
#3
@
16 years ago
- Milestone changed from 2.9 to 2.8
Patch added for this. Also, I think it should go in before 2.9.
This patch changes smilies_init and convert_smilies to make a more efficient regular expression resulting in a ~10times speedup.
This is done by:
o to handle the replacement preg_replace_callback() in convert_smilies.
Resulting generated search regular expression for default smilies:
\?|\?\:|\?\?\?\:|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" |
Load time on the site for a post with 403 comments:
Original: 4.3s
Modified: 2.6s
#4
@
16 years ago
Sorry, slightly old regexp in comment above. There is no 'e' modifier on the end in patch.
#5
@
16 years ago
- Keywords has-patch tested added
Tested all smilies with trunk revision 10308 and 2.6.5
(found and fixed an error in handling smilies like :???: vs :?)
#6
@
16 years ago
Added a proposed test case for smilies (use with http://codex.wordpress.org/Automated_Testing).
Also minor clean ups of patch (removed unused global).
Path deleted.