[wp-trac] [WordPress Trac] #50683: Parse content for shortcodes instead of using regex
WordPress Trac
noreply at wordpress.org
Sat Jul 18 21:34:35 UTC 2020
#50683: Parse content for shortcodes instead of using regex
--------------------------------------+---------------------
Reporter: cfinke | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 5.6
Component: Shortcodes | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+---------------------
Comment (by cfinke):
I've done some performance testing. I created 15 sample shortcodes in
different formats: a simple self-closing shortcode, a set of 10-deep
nested shortcodes, a shortcode with lots of attributes, etc. Then, I
created three sets of random content (short, medium, and long), composed
of random selections of the ASCII keyboard characters except opening and
closing brackets and then added each sample shortcode to each set of
content in four different places: the beginning, middle, end, and at both
the beginning and end. This process creates 195 variations of content.
Then, I tested how long it takes both the current and new `do_shortcode()`
functions to run on all of these content strings.
The total time for the current `do_shortcode()` function was 0.0052
seconds.
The total time for the updated `do_shortcode()` that calls the parser I
wrote was 0.0879 seconds.
The new code is ~17x slower than the current code on this specific
dataset. It looks like the tests that had the worst performance were ones
where a shortcode had sizeable inner content (~4KB), because the new
parser doesn't skip ahead at all when looking at inner content.
I'll take a look at performance improvements and testing the individual
variations between the old and new code.
Note: I'm not sure how this is done normally, so I kind of hacked it by
putting the speed-testing code in a testcase so I could run `phpunit
--group shortcode --filter test_speed` from the command line.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50683#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list