Opened 6 years ago
Last modified 2 months ago
#47322 new defect (bug)
scenario based-bug in the file load-style.php
| Reported by: |
|
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)
Change History (5)
#2
@
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/?
Optimized and better way to stream-out the style contents.