Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 14 years ago

#10987 closed enhancement (fixed)

Improve wptexturize performance

Reported by: johanee's profile johanee Owned by:
Milestone: 2.9 Priority: normal
Severity: major Version: 2.9
Component: Performance Keywords: has-patch
Focuses: Cc:


wptexturize is called for most text shown which makes it highly performance sensitive.

With minimal changes the performance can be improved dramatically:

  1. Make various variables static so they only need to be setup once (instead of 60+ times, on a simple page)
  2. Make wptexturize_pushpop_element more efficient by using what we know about the string to check and improving the regexp strategy

Performance for the suggested patch:

Average total page load time (ab -c 1 -n 100
Clean 2.9.0 revision 12065 install

1 post front page
org: 47ms
fix: 44ms

10 post front page
org: 84ms
fix: 76ms

larger page from real world usage
org: 135ms
fix: 108ms

Attachments (1)

wptexturize-performance.patch (7.7 KB) - added by johanee 15 years ago.
Improve wptexturize performance

Download all attachments as: .zip

Change History (9)

15 years ago

Improve wptexturize performance

#1 @scribu
15 years ago

  • Milestone changed from Unassigned to 2.9

#2 @ryan
15 years ago

Looks good. We'll need to run the texturize unit tests against it.

#3 @johanee
15 years ago

I'll run it as soon as I can but it might not be possible until the weekend: at first glance it looks like I have to upgrade the distribution on my testbox to get PHPUnit installed...

#4 @westi
15 years ago

Here is the output for you :-)

peter-westwoods-computer:wordpress-tests peterwestwood$ php wp-test.php -t TestWPTexturize
Test Suite

Time: 0 seconds

There were 3 failures:

1) test_quotes(TestWPTexturize)
Failed asserting that two strings are equal.
expected string <Here is &#8220;<a href="">a test with a link</a>&#8221;>
difference      <                                                                       x>
got string      <Here is &#8220;<a href="">a test with a link</a>&#8220;>

2) test_quotes_before_s(TestWPTexturize)
Failed asserting that two strings are equal.
expected string <&#8216;string&#8217;>
difference      <     x>
got string      <&#8217;string&#8217;>

3) test_quotes_before_numbers(TestWPTexturize)
Failed asserting that two strings are equal.
expected string <Class of &#8217;99>
difference      <              x>
got string      <Class of &#8216;99>

So it looks like the only regression is to do with the curly quote handling

#5 @johanee
15 years ago

Thank you!

I tested those strings by hand, and the errors exists in current wptexturize too.

The result for these strings are identical when comparing current revision 12083 and patched version.

It looks like test quotes before s was #1258 which was the marked as duplicate of #4539, which is ticket noted in test quotes before numbers so these at least appear to be known problems. I did not immediately find a ticket for test quotes but there might well be -- there are a large number of tickets regarding the subtleties in this function.

That was one reason I've tried to keep the actual parsing identical in this patch.

I'd be happy to look some more at this function but I think fixing these existing problems should be a separate issue and a separate patch.

#6 @westi
15 years ago

My appologies.

I had forgotten that I had added tests for #4539/#1258 which have not yet had a fix applied :-(

#7 @westi
15 years ago

Ok I am going to move the apply_filters calls outside the static setup as plugins could be doing something context sensitive on when this is called.

I wonder if in the long run we should move this into a class and correctly encapsulate the behaviour rather than lots of static variables.

#8 @westi
15 years ago

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

(In [12084]) Improve wptexturize performance. Fixes #10987 props johanee.

Note: See TracTickets for help on using tickets.