Make WordPress Core

Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#56758 closed defect (bug) (fixed)

Performance: Avoid extra calls to realpath

Reported by: aristath's profile aristath Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.1 Priority: normal
Severity: normal Version: 6.1
Component: General Keywords: has-patch
Focuses: performance Cc:

Description

The register_block_style_handle function sets a variable with this code: $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
That value never changes, so we can convert that var to be a static variable. By doing so, we can avoid ~200 calls to realpath and wp_normalize_path (more if 3rd-party plugins register styles)

Change History (5)

This ticket was mentioned in PR #3416 on WordPress/wordpress-develop by aristath.


21 months ago
#1

  • Keywords has-patch added

#2 @mukesh27
21 months ago

@aristath PR look good. I left a comment.

#3 @SergeyBiryukov
21 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

#4 @SergeyBiryukov
21 months ago

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

In 54415:

Blocks: Avoid extra calls to realpath() in block scripts and styles registration.

This affects:

  • register_block_script_handle()
  • register_block_style_handle()

Both functions set a variable with this code:

$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );

That value never changes during page load, so we can save it to a static variable. By doing so, we can avoid ~200 calls to realpath() and wp_normalize_path(), or even more if third-party plugins register scripts or styles.

Follow-up to [52291], [52939], [54290], [54291], [54309], [54327].

Props aristath, mukesh27, SergeyBiryukov.
Fixes #56758.

SergeyBiryukov commented on PR #3416:


21 months ago
#5

Thanks for the PR! Merged in r54415.

Note: See TracTickets for help on using tickets.