Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#45930 closed enhancement (fixed)

Improve the performance of emoji iteration in `wp_encode_emoji()` and `wp_staticize_emoji()`

Reported by: johnbillion Owned by: pento
Milestone: 5.1 Priority: normal
Severity: normal Version: 4.9
Component: Emoji Keywords: has-patch commit
Focuses: performance Cc:


The wp_encode_emoji() and wp_staticize_emoji() functions perform a version comparison against the PHP version for every emoji that they iterate over - currently either 1,250 or 2,839 depending on whether the partial or full list of emoji are being iterated.

This behaviour was introduced in [41702].

By moving the PHP version comparison out of the loop, those thousands of comparisons are avoided and the processing time of both functions are reduced by approximately 50%.

1,000 iterations of wp_encode_emoji() before the proposed change: 4.0 seconds.
1,000 iterations of wp_encode_emoji() after the proposed change: 1.9 seconds.

Attachments (1)

45930.patch (1.2 KB) - added by johnbillion 19 months ago.

Download all attachments as: .zip

Change History (6)

19 months ago

#1 @johnbillion
19 months ago

  • Keywords has-patch added

#2 @pento
19 months ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 5.1

Noice. 🙂

If WordPress 5.2 is going to drop PHP<5.6 support, not much point waiting until then, so let's do this in 5.1.

#3 @pento
19 months ago

  • Owner set to pento
  • Status changed from new to accepted

#4 @pento
19 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 44554:

Emoji: Improve performance when encoding or staticizing emoji.

Both wp_encode_emoji() and wp_staticize_emoji() perform a PHP version check when deciding how to apply their behaviour, but this check only needs to happen once, rather than every time in their internal looks.

Moving the check outside of the loop reduces processing time by 50%.

Props johnbillion.
Fixes #45930.

#5 @pento
19 months ago

In 44556:

Emoji: Fix a code formatting error introduced in [44554].

See #45930.

Note: See TracTickets for help on using tickets.