Problem/Motivation

Noticed this when profiling a request that loads a very large number of entities (about 10k) when caches are cold. On that page I was seeing tens of thousands of calls to array_diff/array_keys via the redis cache backend which uses this trait.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3580109

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

catch’s picture

Status: Active » Needs review
StatusFileSize
new364.82 KB
new379.44 KB

Not entirely like for like screenshots, had another patch applied, but you get the idea.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense. Reminds me of that memory cache tag issue where you saw very different profiling results with those array functions, but I suppose it's pretty clear that this is better.

catch’s picture

There will be some xhprof overhead and other things going on, but since we often only have a single cache tag (like entity_field_info on some cache items, a lot of times it's going to be a very small foreach loop.

The cache items with lots of cache tags tends to be page cache / dynamic page cache where you only have one or two on a page, so even if that's faster with the array_diff() (don't think we need to check that), it's not the common case.

I can't remember the memory cache tag issue profiling results at this point, if you remember the issue I wouldn't mind checking I'm not actually contradicting myself...

berdir’s picture

I was thinking of #3559249: Skip cache tag invalidation if no cache items have cache tags in the memory backend and #3559030: Installing from existing config causes massive cache.config population and slow installs, but that didn't seem to include the discussion/differences I remembered, maybe that was a different channel or a different issue.

It's just that while both saw an issue/improvement, it was a much bigger difference for you in your xhprof runs.

I did confirm this a bit with https://3v4l.org/ and it's performance report as well, although I had to go to 100k array items to see a significant memory difference but I also did only one call. https://github.com/sharkdp/hyperfine might be a way to do more reliable comparison. I think it's not really necessary.

catch’s picture

Ahh OK if it's different levels of improvement, and not improvement in different directions, that seems fine yeah, especially given we could be testing things with different sized arrays etc., thanks for confirming, I was slightly paranoid ;)

alexpott’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

I'm guessing this performs much better as $this->tagCache grows and $query_tags is relatively small.

Committed and pushed ba4dc7c4d18 to main and c62f2f846de to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed c62f2f84 on 11.x
    perf: #3580109 Optimise CacheTagsCheckSumTrait::calculateChecksum()
    
    By...

  • alexpott committed ba4dc7c4 on main
    perf: #3580109 Optimise CacheTagsCheckSumTrait::calculateChecksum()
    
    By...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.