Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a page where _filter_url() is 30% of the load time. The content has lots of markup and the $chunks array in _filter_url() ends up with over 5000 items. A simple change from preg_match() to strcasecmp() reduces my page load time for _filter_url() to only 20% of the page time, from 190msec to 120msec.
Comment | File | Size | Author |
---|---|---|---|
#9 | core-D7-filter-url-2056731-9.patch | 525 bytes | douggreen |
| |||
#8 | core-D7-filter-url-2056731-6.patch | 535 bytes | douggreen |
#6 | core-filter-url-2056731-5.patch | 545 bytes | douggreen |
filter-url-1.patch | 544 bytes | douggreen | |
Comments
Comment #1
catchI didn't have as good an example, but this reduced 3.5ms down to 2.6ms on a relatively short page (204 calls to preg_replace() changed to strcasecmp()).
This should be a good improvement on sites with lots of content (hence a high filter cache miss), or sites which have filters that disable the filter cache altogether.
Comment #2
catchComment #3
j0rd CreditAttribution: j0rd commentedDoesn't look like the preg_match needs to be there, unless the chunks have additional characters on the left or right, in which case preg_match() would return 1 and strcasecmp() would return 0.
If that's not the case, and it's faster then looks like a good patch to me.
Comment #4
zero2one CreditAttribution: zero2one commentedChanged the status to needs review so the testbot picks it up.
Comment #6
douggreen CreditAttribution: douggreen commentedDoh! While reviewing patches applied to a client site, I discovered that this had a very stupid problem, $i instead of 1! And 2 years later :( Let's see if this passes tests.
Comment #7
douggreen CreditAttribution: douggreen commentedThe same patch applies to D7 and D8 :)
Comment #8
douggreen CreditAttribution: douggreen commentedWell, it almost applies ... here's the D7 backport
Comment #9
douggreen CreditAttribution: douggreen commentedIt's nice that it applies here, but I'm using these patches with composer and https://github.com/cweagans/composer-patches, so here's another minor fix.