Make WordPress Core

Changes between Initial Version and Version 3 of Ticket #58069


Ignore:
Timestamp:
04/05/2023 01:55:41 PM (18 months ago)
Author:
westonruter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #58069

    • Property Keywords has-patch has-unit-tests added
    • Property Component changed from Editor to Script Loader
  • Ticket #58069 – Description

    initial v3  
    11The `_wp_normalize_relative_css_links()` function is not currently implemented in an optimal way. It is doing a regex match for all instances of `url(...)` in a given CSS, and then for each match it checks if it is a relative URL. If so, it then makes the URL absolute and then does ''another'' global search & replace in the CSS to replace the relative path with the absolute path. This means for every search there is a secondary search. This secondary `str_replace()` can be eliminated by replacing the unitial `preg_match_all()` with a `preg_replace_callback()`. This makes the function run >2x faster when [https://gist.github.com/westonruter/7f916bee3f45ef9307235daefb603e7c benchmarked] being run across each CSS file in Gutenberg and the built-in themes.
     2
     3Essentially the function can be turned from O(n²) to O(n).
    24
    35
     
    68> phpbench run Bench.php --report=default '--iterations=10' '--revs=500'
    79PHPBench (1.2.10) running benchmarks... #standwithukraine
    8 with PHP version 7.4.33, xdebug ❌, opcache ❌
     10with PHP version 7.4.33, xdebug , opcache
    911
    1012\Bench