#28623 closed enhancement (fixed)
Optimize the wptexturize() Loop
Reported by: | miqrogroove | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | normal | Version: | 1.5 |
Component: | Formatting | Keywords: | wptexturize has-patch |
Focuses: | Cc: |
Description
Following on #28575, there are some more things we can do to make this core code run faster:
The ampersand replacement pattern is running inside the loop for no apparent reason. We can get an overall 10% performance boost just by moving that one pattern to after the loop.
_wptexturize_pushpop_element() may be unnecessarily running regex code that could be replaced with simple string searches, for up to 7% performance boost.
Any opportunity to remove or consolidate the $dynamic patterns will improve performance by about 4% per pattern removed.
Attachments (6)
Change History (15)
This ticket was mentioned in IRC in #wordpress-dev by miqrogroove. View the logs.
10 years ago
#5
@
10 years ago
I ran my prior tests from #28575 against trunk and with the second draft of the patch applied, and it's a nice improvement. My test is pretty blunt and not granular, but doing 10 iterations of wptexturize()
for a 1MB post, trunk does it in around 6.2 seconds, and the patch shaves about a second off that time. More granular profiling like what you did on the other ticket will of course be more useful than my test. Seems like a nice step forward, though!
#6
@
10 years ago
- Keywords needs-unit-tests added
Need to add tests for more things like &# and check if there is already a ticket for that.
#7
@
10 years ago
- Keywords has-patch added; needs-unit-tests removed
fwiw, I also attempted to consolidate some of the $dynamic patterns by using preg_replace_callback, but the overhead for that function is so high that it negates most of the benefit of running fewer patterns.
In miqro-28623.6.patch:
- Take the ampersand pattern out of the loop for speed.
- Fix old bugs in the ampersand pattern.
- Refactor _wptexturize_pushpop_element() without PCRE for speed.
- Update unit tests.
First pass at optimizing ampersands and the element stack.