[wp-trac] [WordPress Trac] #56784: Optimization in wp_staticize_emoji function

WordPress Trac noreply at wordpress.org
Mon Oct 10 17:26:32 UTC 2022


#56784: Optimization in wp_staticize_emoji function
--------------------------+-----------------------------
 Reporter:  kac1per       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Emoji         |    Version:  6.0.2
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 In the `wp_staticize_emoji` function there is a piece of code which seems
 to be there to optimize the process, but in fact does the opposite.

 The piece i'm writing about:
 {{{
         // Quickly narrow down the list of emoji that might be in the text
 and need replacing.
         $possible_emoji = array();
         foreach ( $emoji as $emojum ) {
                 if ( false !== strpos( $text, $emojum ) ) {
                         $possible_emoji[ $emojum ] = html_entity_decode(
 $emojum );
                 }
         }
 }}}

 Feeding all of 3575 emoji enitities into `strpos` function generates much
 more overhead than passing all existing emojis for further processing.
 This can be easily observed by entirely skipping the `false !== strpos(
 $text, $emojum )` check and adding all entities to `$possible_emoji` array
 – the whole execution of the `wp_staticize_emoji` function becomes nearly
 10x faster. This effect happened to me every time I tested it no matter
 the content or length of the passed text.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56784>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list