Make WordPress Core

Opened 6 years ago

Last modified 2 months ago

#47322 new defect (bug)

scenario based-bug in the file load-style.php

Reported by: asimbaki's profile asimbaki Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.2
Component: Script Loader Keywords: needs-patch
Focuses: performance Cc:

Description

Technically the file load-style.php has a bug, however it is a scenario based-bug so it rarely occurred. Not going in to so much details of PHP the problem is with the variable $out concatenation of "$contents" used in the foreach loop, i.e., O(n) complexity issue - the allocated buffer is exhausted assigned by PHP during the single http request execution.

The better and optimized way is:

move the "header" just the above "foreach ( $load as $handle )" loop statement.
remove "$out" , i.e., echo $content rather concatenating into $out.

I had this issue during installing app on my local machine, and solved it happily by doing changes that way.

Attachments (1)

load-styles.php (2.2 KB) - added by asimbaki 6 years ago.
Optimized and better way to stream-out the style contents.

Download all attachments as: .zip

Change History (5)

@asimbaki
6 years ago

Optimized and better way to stream-out the style contents.

#1 @SergeyBiryukov
6 years ago

  • Component changed from General to Script Loader

#2 @jonsurrell
3 months ago

Reviewing the code of load-styles.php and for load-scripts.php as well, this does seem like a reasonable optimization.

  • It appears that all data for the headers is ready to be sent before processing the styles or scripts.
  • It appears that no additional processing happens after the loop.

Instead of concatenating all of the styles/scripts into a string, then printing the entire string at once, each chunk can be printed to be sent in the response.

@asimbaki, are you interested in preparing a patch or PR on https://github.com/wordpress/wordpress-develop/?

#3 @jonsurrell
3 months ago

  • Focuses performance added

#4 @westonruter
2 months ago

Note that dynamic concatenation of scripts and styles has been proposed for deprecation/removal in #57548.

Note: See TracTickets for help on using tickets.