Make WordPress Core

Opened 20 months ago

Closed 20 months ago

Last modified 20 months 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.


20 months ago
#1

  • Keywords has-patch added

#3 @SergeyBiryukov
20 months 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:


20 months ago
#4

Thanks for the PR! Merged in r54327.

#5 @milana_cap
20 months ago

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