Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#56636 closed defect (bug) (fixed)

Bug/performance: duplicate use of realpath()

Reported by: aristath Owned by: SergeyBiryukov
Priority: normal Milestone: 6.1
Component: General Version: 6.1
Severity: normal Keywords: has-patch add-to-field-guide
Cc: Focuses: performance

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.


4 years 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
4 years ago

  • Summary Performance: duplicate use of realpath() → Bug/performance: duplicate use of realpath()

#3 @aristath
4 years ago

  • Description modified (diff)

#4 @SergeyBiryukov
4 years ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → 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:


4 years ago
#5

Thanks for the PR! Merged in r54290.

#6 @milana_cap
4 years ago

  • Keywords add-to-field-guide added

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


4 years ago

Note: See TracTickets for help on using tickets.