Make WordPress Core

Opened 4 weeks ago

Closed 4 weeks ago

Last modified 4 weeks ago

#62063 closed enhancement (fixed)

traverse_and_serialize_blocks calls is_callable for each block instance

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

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.


4 weeks 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
4 weeks 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:


4 weeks 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
4 weeks ago

  • Component changed from General to Editor
  • Milestone changed from Awaiting Review to 6.7
  • Version set to 6.4

Introduce in [56644].

Ping @bernhard-reiter for review.

#5 @SergeyBiryukov
4 weeks ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to 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:


4 weeks ago
#6

Thanks for the PR! Merged in r59077.

Note: See TracTickets for help on using tickets.