#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:
- Make various variables static so they only need to be setup once (instead of 60+ times, on a simple page)
- 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)
Change History (9)
#2
@
15 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
#3
@
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
@
15 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 “<a href="http://example.com">a test with a link</a>”> difference < x> got string <Here is “<a href="http://example.com">a test with a link</a>“> /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 <‘string’> difference < x> got string <’string’> /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 ’99> difference < x> got string <Class of ‘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
#5
@
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.
#7
@
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.
Improve wptexturize performance