Make WordPress Core

Changeset 54415


Ignore:
Timestamp:
10/07/2022 03:44:31 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r54330 r54415  
    130130
    131131    // Path needs to be normalized to work in Windows env.
    132     $wpinc_path_norm  = wp_normalize_path( realpath( ABSPATH . WPINC ) );
     132    static $wpinc_path_norm = '';
     133    if ( ! $wpinc_path_norm ) {
     134        $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
     135    }
     136
    133137    $theme_path_norm  = wp_normalize_path( get_theme_file_path() );
    134138    $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) );
     
    183187    }
    184188
    185     $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
     189    static $wpinc_path_norm = '';
     190    if ( ! $wpinc_path_norm ) {
     191        $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
     192    }
    186193
    187194    $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
Note: See TracChangeset for help on using the changeset viewer.