Opened 2 years ago
Last modified 4 weeks ago
#56784 new defect (bug)
Optimization in wp_staticize_emoji function
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.0.2 |
Component: | Emoji | Keywords: | needs-patch |
Focuses: | performance | Cc: |
Description
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.
Change History (3)
#3
@
3 months ago
I ran some tests to compare the old function and the new suggested function, but the improvement wasn’t significant. However, I’m not entirely confident in my testing process, so I believe it would be beneficial to conduct standard and more rigorous testing to move ahead with this issue.
Thanks for this one, @kac1per.
It seems that the code block you're referencing is there to ensure both the encoded and decoded versions of the emoji are available further down. So only skipping the condition would not be the full solution.
Could you prepare a patch or pull request demonstrating your suggested changes? This will help make it more clear to everyone viewing this ticket and allow the automated tests to run.