Make WordPress Core

Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#56637 closed defect (bug) (fixed)

Bug/performance: Repetitive calls to file_get_contents

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

While running tests with Xdebug & web grind, I identified repetitive calls to file_get_contents() from the get_default_block_editor_settings() function.
That function repeatedly gets the contents of the /css/dist/block-editor/default-editor-styles.css without any implementation to avoid those.

This is an easy bugfix, and involves using a static variable in the function. Details and screenshots in the PR.

Change History (10)

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


20 months ago
#1

  • Keywords has-patch added

Fixes repeat calls to file_get_contents

Testing on WP 6.1 (trunk), on the front-page of a site using Xdebug & webgrind: (values in milliseconds)

Before the patch:

https://i0.wp.com/user-images.githubusercontent.com/588688/191936131-9a66ac4a-a3c2-490f-bb5f-347b7c35d92d.png

After the patch:

https://i0.wp.com/user-images.githubusercontent.com/588688/191936238-c695a818-2e04-4188-91e7-09304ba5227e.png

Invocation count goes down from 181 to 93. Total self-cost goes down from 160ms to ~2ms

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

#2 @aristath
20 months ago

Edit: There was an error in the 2nd screenshot above.
Total self-cost goes down from 160ms to 93ms, not 1.88 (I forgot to switch from % to ms values in the after image)
Screenshot & text updated in the PR, but these changes don't get reflected in the comment above from the Github-sync bot.

mukeshpanchal27 commented on PR #3318:


20 months ago
#3

@aristath Left one comment. Does that make sense to you?

#4 follow-up: @mukesh27
20 months ago

Is it specific to Editor or General component ticket?

#5 in reply to: ↑ 4 @aristath
20 months ago

Replying to mukesh27:

Is it specific to Editor or General component ticket?

General. The get_default_block_editor_settings() function runs on the frontend as well (it's used in the JSON resolver), so the impact is global and not just the editor

#6 @mukesh27
20 months ago

Ok thanks.

PR #3318 looks good to me.
Thanks @aristath

#7 @SergeyBiryukov
20 months ago

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

In 54291:

Block Editor: Remove repetitive calls to file_get_contents() in block editor settings.

The get_default_block_editor_settings() function used to repeatedly get the default-editor-styles.css file contents without any implementation to avoid this.

This commit utilizes a static variable to remove repetitive calls made during the same request. In tests ran on the front page of a site using Xdebug & Webgrind, the total file_get_contents() invocation count goes down from 181 to 93, and total self cost (the time that the function is responsible for) goes down from 160 ms to 93 ms.

Follow-up to [52042].

Props aristath, mukesh27.
Fixes #56637.

SergeyBiryukov commented on PR #3318:


20 months ago
#8

Thanks for the PR! Merged in r54291.

#9 @milana_cap
20 months ago

  • Keywords add-to-field-guide added

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


20 months ago

Note: See TracTickets for help on using tickets.