Make WordPress Core

Opened 5 weeks ago

Closed 5 weeks ago

Last modified 3 weeks ago

#60749 closed defect (bug) (fixed)

Interactivity API: Avoid unnecessary processing of directives

Reported by: joemcgill's profile joemcgill Owned by: swissspidy's profile swissspidy
Milestone: 6.5 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch commit fixed-major dev-reviewed
Focuses: performance Cc:

Description

During performance reviews on 6.5, it was discovered that processing directives of interactive blocks can sometimes be the source of degraded performance.

This is because all block types that support interactivity are getting processed by wp_interactivity_process_directives_of_interactive_blocks even if the block markup didn't contain the necessary data-wp- markup necessary for processing, resulting in unnecessary calls to wp_interactivity_process_directives which make heavy use of the WP_HTML_Tag_Processor.

We should try to avoid this unnecessary processing if possible.

Change History (11)

This ticket was mentioned in PR #6251 on WordPress/wordpress-develop by @joemcgill.


5 weeks ago
#1

  • Keywords has-patch added

This is a modified PR based on @gziolo's initial approach in this Slack thread.

The main change from his original proposal is to use str_contains() instead of str_pos() given that we have a polyfill for this in Core now. This reduces calls to wp_interactivity_process_directives() on the Twenty Twenty-four homepage from 9 to 1 along with memory consumption related to the WP_HTML_Tag_Processor.

https://github.com/WordPress/wordpress-develop/assets/801097/e61e27c8-4d6b-41e5-b4cb-2cc50b401c1e

Trac ticket: https://core.trac.wordpress.org/ticket/60749

This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.


5 weeks ago

This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.


5 weeks ago

#4 @joemcgill
5 weeks ago

  • Focuses performance added

#5 @gziolo
5 weeks ago

  • Keywords dev-reviewed added

@swissspidy, it would be nice to have this fix included as well.

#6 @swissspidy
5 weeks ago

  • Component changed from General to Editor
  • Keywords commit dev-feedback added; dev-reviewed removed
  • Priority changed from high to normal

#7 @swissspidy
5 weeks ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 57824:

Interactivity API: Do not process directives when there aren’t any.

Short-circuits directive processing when the markup does not actually contain any data-wp-* attributes.
This reduces function calls and memory usage for the best case scenario due to not involving WP_HTML_Tag_Processor.

Props joemcgill, swissspidy, gziolo, cbravobernal, flixos90.
Fixes #60749.

#8 @swissspidy
5 weeks ago

  • Keywords fixed-major dev-reviewed added; dev-feedback removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

#9 @swissspidy
5 weeks ago

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

In 57825:

Interactivity API: Do not process directives when there aren't any.

Short-circuits directive processing when the markup does not actually contain any data-wp-* attributes.
This reduces function calls and memory usage for the best case scenario due to not involving WP_HTML_Tag_Processor.

Reviewed by gziolo, swissspidy.
Merges [57824] to the to the 6.5 branch.

Props joemcgill, swissspidy, gziolo, cbravobernal, flixos90.
Fixes #60749.

#11 @gziolo
3 weeks ago

I'm playing with another idea when I completely avoid using hooks by moving the logic to the WP_Block class:

https://github.com/WordPress/wordpress-develop/pull/6331

Note: See TracTickets for help on using tickets.