Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#62063 closed enhancement (fixed)

traverse_and_serialize_blocks calls is_callable for each block instance

Reported by: welcher Owned by: SergeyBiryukov
Priority: normal Milestone: 6.7
Component: Editor Version: 6.4
Severity: normal Keywords: has-patch
Cc: Focuses: performance

Description

In the traverse_and_serialize_blocks function, the second and third parameters are checked for null for each block in the loop. This check can be done instead once when the function is invoked and cached in variables.

Change History (6)

This ticket was mentioned in ​PR #7387 on ​WordPress/wordpress-develop by ​@welcher.


2 years ago
#1

  • Keywords has-patch added

This PR caches the is_callable calls in traverse_and_serialize_blocks rather than calling it for each iteration of the foreach loop. This should improve the performance of the function.

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

#2 @welcher
2 years ago

If this is approved/merged, can we please add Cybr to the props as they brought this to my attention and deserve to share credit.

​@mukesh27 commented on ​PR #7387:


2 years ago
#3

I did some profiling and found that it reduce total call count for is_callable function and reduce wall time.

Before:
https://github.com/user-attachments/assets/431ec229-affb-4168-b2ba-39e1c813dc3a

After:
https://github.com/user-attachments/assets/6bb981e6-93a4-4937-99d8-7a530eba3d01

FYI i test TT4 blog page.

#4 @mukesh27
2 years ago

  • Component General → Editor
  • Milestone Awaiting Review → 6.7
  • Version → 6.4

Introduce in [56644].

Ping @bernhard-reiter for review.

#5 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → closed

In 59077:

Editor: Optimize is_callable() checks in traverse_and_serialize_blocks().

This aims to improve performance by reducing the number of function calls.

Follow-up to [56644].

Props welcher, Cybr, mukesh27, aristath.
Fixes #62063.

​@SergeyBiryukov commented on ​PR #7387:


2 years ago
#6

Thanks for the PR! Merged in r59077.

Note: See TracTickets for help on using tickets.