WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10987 closed enhancement (fixed)

Improve wptexturize performance

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

Description

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 http://example.org/)
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 5 years ago.
Improve wptexturize performance

Download all attachments as: .zip

Change History (9)

@johanee5 years ago

Improve wptexturize performance

comment:1 @scribu5 years ago

  • Milestone changed from Unassigned to 2.9

comment:2 @ryan5 years ago

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

http://svn.automattic.com/wordpress-tests/wp-testcase/test_includes_formatting.php

comment:3 @johanee5 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...

comment:4 @westi5 years ago

Here is the output for you :-)

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

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="http://example.com">a test with a link</a>&#8221;>
difference      <                                                                       x>
got string      <Here is &#8220;<a href="http://example.com">a test with a link</a>&#8220;>
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-testcase/test_includes_formatting.php:318
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-testlib/base.php:526
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-test.php:107

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;>
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-testcase/test_includes_formatting.php:329
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-testlib/base.php:526
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-test.php:107

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>
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-testcase/test_includes_formatting.php:335
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-testlib/base.php:526
/Users/peterwestwood/Documents/workspace/wordpress-tests/wp-test.php:107

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

comment:5 @johanee5 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.

comment:6 @westi5 years ago

My appologies.

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

comment:7 @westi5 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.

comment:8 @westi5 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.