Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years 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.


2 years ago
#1

  • Keywords has-patch added

#2 @mukesh27
2 years ago

@aristath PR look good. I left a comment.

#3 @SergeyBiryukov
2 years ago

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

#4 @SergeyBiryukov
2 years 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:


2 years ago
#5

Thanks for the PR! Merged in r54415.

Note: See TracTickets for help on using tickets.