Ticket #6464 (closed defect (bug): fixed)

Opened 4 years ago

Last modified 3 years ago

convert_smilies is very slow

Reported by: Acci Owned by: anonymous
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

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

Change History

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

Acci4 years ago

comment:2   Acci4 years ago

  • Keywords has-patch needs-testing removed

Path deleted.

johanee3 years ago

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 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

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 :?)

johanee3 years ago

Faster regexp and uses preg_replace_callback(), tested, fixed

johanee3 years ago

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

johanee3 years ago

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).

  • Cc johan.eenfeldt@… added

comment:8   ryan3 years ago

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

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

(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.