[wp-trac] [WordPress Trac] #47514: Change priority of make_clickable callback to boost performance
    WordPress Trac 
    noreply at wordpress.org
       
    Wed Jun 12 18:58:25 UTC 2019
    
    
  
#47514: Change priority of make_clickable callback to boost performance
-------------------------+------------------------------
 Reporter:  olliverh87   |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Comments     |     Version:  5.2.1
 Severity:  minor        |  Resolution:
 Keywords:               |     Focuses:  performance
-------------------------+------------------------------
Comment (by olliverh87):
 Hi @SergeyBiryukov ,
 thank you so much for your feedback! I did not think of this scenario,
 please let me apologize.
 It seems that {{{force_balance_tags}}} does a great job at producing
 mostly valid markup, so to address the issue with the test case you
 showed, it seems to be the easiest solution to make a trade off and have
 make_clickable run after the other filters (such as {{{convert_smilies}}}
 but run before {{{force_balance_tags}}}.
 I added the following snippet to the {{{functions.php}}} file of my active
 theme on my test-setup to do some performance measurements:
 {{{#!php
 <?php
 add_action('init', function() {
     $comment_string = "x " . str_repeat("ftp.x ", 10916);
     // 1st test, run with default configuration
     $default_time = microtime(true);
     apply_filters('comment_text', $comment_string);
     $default_time = microtime(true) - $default_time;
     //2nd test, run with changed priorities (make_clickable before
 force_balance_tags)
     remove_filter('comment_text', 'make_clickable', 9);
     add_filter('comment_text', 'make_clickable', 24);
     $changed_time = microtime(true);
     apply_filters('comment_text', $comment_string);
     $changed_time = microtime(true) - $changed_time;
     // echo results
     echo "Default configuration runtime: " . $default_time . " secs" .
 "<br />";
     echo "Changed configuration runtime: " . $changed_time . " secs" .
 "<br /> <br />";
     exit;
 });
 }}}
 Running it for a 100 times showed this modification increases performance
 by ~23% on average, while still producing valid markup as addressed with
 your test case. What do you think?
 The diff would then become:
 {{{
 --- a.php       2019-06-09 22:47:58.744746903 +0200
 +++ b.php       2019-06-09 22:49:00.080742874 +0200
 @@ -190,7 +190,7 @@
  add_filter( 'comment_text', 'wptexturize' );
  add_filter( 'comment_text', 'convert_chars' );
 -add_filter( 'comment_text', 'make_clickable', 9 );
 +add_filter( 'comment_text', 'make_clickable', 24 );
  add_filter( 'comment_text', 'force_balance_tags', 25 );
  add_filter( 'comment_text', 'convert_smilies', 20 );
  add_filter( 'comment_text', 'wpautop', 30 );
 }}}
-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47514#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
    
    
More information about the wp-trac
mailing list