Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#56666 closed defect (bug) (fixed)

Bug/performance: No need to make repeat calls to `get_theme_file_path` in `register_block_style_handle`

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 add-to-field-guide
Focuses: performance Cc:

Description

The register_block_style_handle function runs ~200 times on each page load.
Each time it runs, we call get_theme_file_path and then run it through wp_normalize_path.
get_theme_file_path calls get_stylesheet_directory, which calls get_stylesheet, which calls get_option, and there's a bunch of filters that run on each iteration of that - without ever changing.

We can cache the value and avoid 200 calls on many functions and filters - improving performance.

Change History (5)

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


2 years ago
#1

  • Keywords has-patch added

#3 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 54327:

Blocks: Remove extra get_theme_file_path() calls in register_block_style_handle().

The register_block_style_handle() function runs ~200 times on each page load. Each time it runs, we call get_theme_file_path() and then run it through wp_normalize_path().

get_theme_file_path() calls a few other functions: get_stylesheet_directory(), get_stylesheet(), get_option(), and there's a bunch of filters that run on each iteration of that, without ever changing.

By caching the value in a static variable, we can avoid ~200 calls on many functions and filters, improving performance.

Follow-up to [53091], [54290], [54291], [54309].

Props aristath, mukesh27.
Fixes #56666.

SergeyBiryukov commented on PR #3341:


2 years ago
#4

Thanks for the PR! Merged in r54327.

#5 @milana_cap
2 years ago

  • Keywords add-to-field-guide added
Note: See TracTickets for help on using tickets.