Make WordPress Core

Opened 17 years ago

Closed 16 years ago

Last modified 16 years ago

#6464 closed defect (bug) (fixed)

convert_smilies is very slow

Reported by: acci's profile 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)

6464.diff (9 bytes) - added by Acci 17 years ago.
faster-smilies2.patch (4.5 KB) - added by johanee 16 years ago.
Faster regexp and uses preg_replace_callback()
faster-smilies3.patch (4.7 KB) - added by johanee 16 years ago.
Faster regexp and uses preg_replace_callback(), tested, fixed
faster-smilies4.patch (5.1 KB) - added by johanee 16 years ago.
Faster regexp and uses preg_replace_callback(), tested, fixed, minor cleaning
test_smilies.php (5.5 KB) - added by johanee 16 years ago.
Test case for smilies, for use with Wordpress Test

Download all attachments as: .zip

Change History (14)

#1 @Nazgul
17 years ago

  • Keywords has-patch needs-testing added
  • Milestone changed from 2.7 to 2.6

@Acci
17 years ago

#2 @Acci
17 years ago

  • Keywords has-patch needs-testing removed

Path deleted.

@johanee
16 years ago

Faster regexp and uses preg_replace_callback()

#3 @johanee
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 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 preg_replace_callback() in convert_smilies.

Resulting generated search regular expression for default smilies:

"/(\s|)8(\)\)O|O)|\:(\!\:|\(|\)\(\)\?DPox\
\?|\?\:|\?\?\?\:|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 @johanee
16 years ago

Sorry, slightly old regexp in comment above. There is no 'e' modifier on the end in patch.

#5 @johanee
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 :?)

@johanee
16 years ago

Faster regexp and uses preg_replace_callback(), tested, fixed

@johanee
16 years ago

Faster regexp and uses preg_replace_callback(), tested, fixed, minor cleaning

@johanee
16 years ago

Test case for smilies, for use with Wordpress Test

#6 @johanee
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).

#7 @johanee
16 years ago

  • Cc johan.eenfeldt@… added

#8 @ryan
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10322]) Faster smilies. Props johanee. fixes #6464

#9 @azaozz
16 years ago

(In [10514]) Require smilies to be surrounded by spaces or be at the beginning or end of the line, see #6464

Note: See TracTickets for help on using tickets.