Ticket #6464 (closed defect (bug): fixed)
convert_smilies is very slow
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.8 |
| Component: | Optimization | Version: | |
| Severity: | normal | Keywords: | has-patch, tested |
| Cc: | johan.eenfeldt@… |
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
Change History
- Keywords has-patch needs-testing added
- Milestone changed from 2.7 to 2.6
-
attachment
faster-smilies2.patch
added
Faster regexp and uses preg_replace_callback()
- 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
Sorry, slightly old regexp in comment above. There is no 'e' modifier on the end in patch.
- 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 :?)
-
attachment
faster-smilies3.patch
added
Faster regexp and uses preg_replace_callback(), tested, fixed
-
attachment
faster-smilies4.patch
added
Faster regexp and uses preg_replace_callback(), tested, fixed, minor cleaning
-
attachment
test_smilies.php
added
Test case for smilies, for use with Wordpress Test
Added a proposed test case for smilies (use with http://codex.wordpress.org/Automated_Testing).
Also minor clean ups of patch (removed unused global).
- Status changed from new to closed
- Resolution set to fixed
