Make WordPress Core

Opened 19 months ago

Closed 18 months ago

Last modified 18 months ago

#58342 closed enhancement (fixed)

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 19 months ago.
Replaced register_block_type with register_block_type_from_metadata
58342-2.diff (541 bytes) - added by nihar007 19 months ago.
This time I followed pre-defined coding standards

Download all attachments as: .zip

Change History (14)

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


19 months ago

@nihar007
19 months ago

Replaced register_block_type with register_block_type_from_metadata

#2 @mukesh27
19 months 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
19 months ago

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

@nihar007
19 months ago

This time I followed pre-defined coding standards

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


19 months ago
#4

  • Keywords has-patch added; needs-refresh removed

#5 @mukesh27
19 months ago

Thanks @nihar007 and @sudipatel007 for the patch.

#6 @spacedmonkey
19 months ago

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

#7 @gziolo
19 months ago

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

#8 @spacedmonkey
19 months 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
19 months 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
18 months 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.

#11 @spacedmonkey
18 months ago

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

In 55879:

Editor: Use register_block_type_from_metadata in register_core_block_types_from_metadata.

Use register_block_type_from_metadata in register_core_block_types_from_metadata function instead of register_block_type. This saves an unnecessary call to file_exists in register_block_type as core block files will always exist.

Props nihar007, spacedmonkey, mukesh27, gziolo, sudipatel007.
Fixes #58342.

@spacedmonkey commented on PR #4488:


18 months ago
#12

Committed.

Note: See TracTickets for help on using tickets.