Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

WP-r55888: Script Loader: Improve performance of wp_maybe_inline_styles function. #272

Merged
merged 4 commits into from
Nov 12, 2023

Conversation

mattyrob
Copy link
Collaborator

@mattyrob mattyrob commented Oct 31, 2023

Description

Script Loader: Improve performance of wp_maybe_inline_styles function.

The wp_maybe_inline_styles function is called twice on the average page load. On it's second run however, it did not check to see if the style had already been processed on the first run. This resulted in calling filesize and get_file_contents unnecessarily, which was bad for performance. Now, the loop around the queued styles, checks to see if the source is set to false, meaning it has already been processed. This change also replaces calls to filesize with the core function wp_filesize, which improves extensibility.

Props spacedmonkey, flixos90, peterwilsoncc, joemcgill.

https://core.trac.wordpress.org/changeset/55888

Motivation and context

Backport of upstream efficiency enhancement

How has this been tested?

This is a backport, local tests have been passing.

Screenshots

N/A

Types of changes

  • Code efficiency enhancement

spacedmonkey and others added 4 commits October 31, 2023 16:56
…es function.

The `wp_maybe_inline_styles` function is called twice on the average page load. On it's second run however, it did not check to see if the style had already been processed on the first run. This resulted in calling `filesize` and `get_file_contents` unnecessarily, which was bad for performance. Now, the loop around the queued styles, checks to see if the source is set to false, meaning it has already been processed. This change also replaces calls to `filesize` with the core function `wp_filesize`, which improves extensibility.

WP:Props spacedmonkey, flixos90, peterwilsoncc, joemcgill.
Fixes https://core.trac.wordpress.org/ticket/58394.

Conflicts:
- tests/phpunit/tests/dependencies/styles.php

---

Merges https://core.trac.wordpress.org/changeset/55888 / WordPress/wordpress-develop@582ddb82f4 to ClassicPress.
…n wp_maybe_inline_styles.

Add a check in `wp_maybe_inline_styles` to check that style is registered before processing items in queue. It is possible that developers may have called `wp_deregister_style`, unregistering style but the style still be in the queue to be processed. Without this check, typing to access the `src` property would result in a notice error.

Follow on from https://core.trac.wordpress.org/changeset/55888.

WP:Props spacedmonkey, flixos90, dd32, kebbet.
See https://core.trac.wordpress.org/ticket/58394.

---

Merges https://core.trac.wordpress.org/changeset/55909 / WordPress/wordpress-develop@559e6cecf4 to ClassicPress.
Copy link
Member

@xxsimoxx xxsimoxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@viktorix viktorix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@mattyrob
Copy link
Collaborator Author

Has two approvals, merging in preparation for v2 repository migration.

@mattyrob mattyrob merged commit b57233d into develop Nov 12, 2023
10 checks passed
@mattyrob mattyrob deleted the merge/wp-r55888 branch November 12, 2023 11:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants