Make WordPress Core

Opened 2 weeks ago

Last modified 2 days ago

#58342 assigned enhancement

Use register_block_type_from_metadata in register_core_block_types_from_metadata

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.3 Priority: high
Severity: normal Version: 5.5
Component: Editor Keywords: good-first-bug has-patch commit
Focuses: performance Cc:

Description

In register_core_block_types_from_metadata function, register_block_type is called. This does a file_exists check and then calls register_block_type_from_metadata. However, register_block_type_from_metadata can be called directly with the same effect. This saves around 21 files exists checks and results in improved performance.

Attachments (2)

58342.diff (639 bytes) - added by nihar007 2 weeks ago.
Replaced register_block_type with register_block_type_from_metadata
58342-2.diff (541 bytes) - added by nihar007 11 days ago.
This time I followed pre-defined coding standards

Download all attachments as: .zip

Change History (12)

This ticket was mentioned in Slack in #core-editor by spacedmonkey. View the logs.


2 weeks ago

@nihar007
2 weeks ago

Replaced register_block_type with register_block_type_from_metadata

#2 @mukesh27
11 days ago

  • Keywords needs-refresh added

Thanks @nihar007 for the Patch!

Your patch has PHPCS error. Instead of arrange in single line just replace register_block_type with register_block_type_from_metadata function.

#3 @nihar007
11 days ago

Thanks for your feedback.
I got it.
I am patching once again after fixing this.

@nihar007
11 days ago

This time I followed pre-defined coding standards

This ticket was mentioned in PR #4488 on WordPress/wordpress-develop by sudip-md.


11 days ago
#4

  • Keywords has-patch added; needs-refresh removed

#5 @mukesh27
11 days ago

Thanks @nihar007 and @sudipatel007 for the patch.

#6 @spacedmonkey
10 days ago

I would love the thoughts of @gziolo @youknowriad on this change.

#7 @gziolo
8 days ago

The changes proposed make sense. In retrospect, the direct call seems like a reasonable choice in WordPress Core.

#8 @spacedmonkey
7 days ago

@gziolo Would there ever be a case where there are core blocks without block.json? I am guessing not.

I am good to commit this then?

#9 @gziolo
7 days ago

Good to commit. All core blocks need to have block.json. It's also optimized behind the scenes, and all core blocks have block.json transformed into a single PHP file during the build process to avoid reading and parsing all individual JSON files.

#10 @spacedmonkey
2 days ago

  • Keywords commit added
  • Milestone changed from Future Release to 6.3
  • Owner set to spacedmonkey
  • Priority changed from normal to high
  • Status changed from new to assigned

Making this as ready for commit.

This is not just a code quality change. This change removes 31 calls to file exists, so this change has a performance benefit. Flagging the performance lead @flixos90 for review.

Note: See TracTickets for help on using tickets.