Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#56636 closed defect (bug) (fixed)

Bug/performance: duplicate use of 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 add-to-field-guide
Focuses: performance Cc:

Description (last modified by aristath)

While running Xdebug profiling with webgring in WP-Core, I noticed that realpath() is getting called too many times and costs a lot of time.
After some examination, I found that the register_block_style_handle() function calls realpath to set a $style_path_norm variable, and then a few lines below that, sets a $style_file variable with the exact same value, recalculating things and re-running realpath.

This is a simple bugfix and saves some performance. More details and screenshots in the PR

Change History (7)

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


19 months ago
#1

  • Keywords has-patch added

This patch removes duplicate calculations for a variable, reducing by half the number of times we call realpath().

Tests ran using Xdebug & webgind, attaching screenshots of the reports:

Before the patch:

https://i0.wp.com/user-images.githubusercontent.com/588688/191922115-5a1d3611-c683-4e26-887b-80dc2809fa05.png

After the patch:

https://i0.wp.com/user-images.githubusercontent.com/588688/191922218-ce423a27-86d8-461e-b41c-277d22f712e7.png

Invocation count goes down from 639 to 461. Total self-cost goes down from 146ms to 89ms (values shown are in milliseconds).

Trac ticket: https://core.trac.wordpress.org/ticket/56636

#2 @aristath
19 months ago

  • Summary changed from Performance: duplicate use of realpath() to Bug/performance: duplicate use of realpath()

#3 @aristath
19 months ago

  • Description modified (diff)

#4 @SergeyBiryukov
19 months ago

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

In 54290:

Blocks: Remove duplicate use of realpath() in register_block_style_handle().

The register_block_style_handle() function called realpath() when retrieving the normalized style path, and then a few lines below that, recalculated the exact same value, running realpath() again.

This commit removes duplicate calculations, reducing the number of realpath() calls in the function by half. In tests ran using Xdebug & Webgrind, the total realpath() invocation count goes down from 639 to 461, and total self cost (the time that the function is responsible for) goes down from 146 ms to 89 ms.

Follow-up to [48141], [52291], [53091], [54155].

Props aristath.
Fixes #56636.

SergeyBiryukov commented on PR #3317:


19 months ago
#5

Thanks for the PR! Merged in r54290.

#6 @milana_cap
19 months ago

  • Keywords add-to-field-guide added

This ticket was mentioned in Slack in #core by sergey. View the logs.


19 months ago

Note: See TracTickets for help on using tickets.