Review main Merged

76384[TASK] Drop ineffective TMENU caches

Loek Hilgersom CR +2 V +2 Easy +6 −33 updated 11/04/22, 13:23

Commit message

The "hash" cache for (TMENU) menu generation is
very ineffective: The cache identifier hash contains
the page rootline, so it is single page specific.

This leads to quite some pollution of the "hash"
cache, often many more entries than page cache
entries, without high re-use / cache-hit rate.

Looking closer at this, we found the menu
generation cache to be so ineffective that it's
better to not cache at all. We first thought a
runtime cache would be a good solution but even
that one is not helpful and there are further
runtime caches on lower levels already, for
instance to resolve shortcut pages.

The patch removes this cache layer, leading to
a drastically smaller "hash" cache.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Loek Hilgersom +1
    • Christian Kuhn +1
  • Verified V +2 Done
    • Benni Mack +2
    • Loek Hilgersom +1
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 2936

Show 1011 earlier messages
  1. Loek Hilgersom uploaded patch set 1 11/02/22, 14:50

  2. core-ci voted on patch set 1 V -1 11/02/22, 15:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/32989

  3. Benni Mack commented on patch set 1 11/02/22, 15:09

    Hey loek, I suggest to use a typoscript setting for this?
  4. Loek Hilgersom commented on patch set 1 11/02/22, 15:25

    Reply

    What do you mean exactly, and why? 1 general TS setting, or 1 for each menu? Do you think people might want to use caching for some menus but not all? Or for some sites in a TYPO3 instance, and others not? To me this sounds like a system-wide preference, but I'd like to hear your thoughts on this.
  5. Benni Mack commented on patch set 1 11/02/22, 21:42

    Looking at the generated hash, I have to say that the cache is really "nonsense" nowadays. The hash contains the rootline of the frontend, so re-using the cached entry is highly unlikely and does not fit the actual usage of what should be done, I am therefore proclaiming that we could drop the cache functionality alltogether.
  6. Christian Kuhn commented on patch set 1 11/03/22, 10:14

    Reply

    I added some breakpoints and checked the bootstrap_package: When rendering a page, there are various cache-hits. It looks as if this happens especially when menu-configs create empty strings. If there are multiple menus like that on a page, caching may be useful. However, I'm unsure if generating 'empty' menus is expensive in the first place. I'd propose to use the runtime cache instead: This avoids the select+insert queries and comes with very little overhead. These cache entries are always page-specific (because rootline is in the identifier hash), so as long as menus are not _INT objects, a page-specific persisted cache is not beneficial, just eats queries and increases the hash-cache without benefit. runtime-cache instead is call-specific and should work quite well in this case? What do you think?
  7. Christian Kuhn commented on patch set 1 CR -1 11/03/22, 11:37

    i'll push on this to go with the runtime-cache approach.
  8. Christian Kuhn uploaded patch set 2 11/03/22, 12:35

  9. Christian Kuhn uploaded patch set 3 11/03/22, 12:39

  10. Christian Kuhn commented on patch set 3 11/03/22, 12:39

    Reply

    Done

    Reply

    Done
  11. Christian Kuhn updated the commit message in patch set 4 11/03/22, 12:40

  1. core-ci voted on patch set 2 V +1 11/03/22, 12:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33040

  2. core-ci voted on patch set 4 V +1 11/03/22, 12:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33042

  3. core-ci voted on patch set 3 V +1 11/03/22, 12:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33041

  4. Christian Kuhn voted on patch set 4 V +1 CR +1 11/03/22, 13:44

  5. Christian Kuhn commented on patch set 4 11/03/22, 13:44

    imho fine, but lets wait for some more reviews.
  6. Loek Hilgersom commented on patch set 4 CR -1 11/03/22, 15:33

    Thinking about the patch again: we found that every time the cache is retrieved, the result is an empty array. So, eventhough the runtime cache may be an improvement to the former persistent cache, what is happening now is that all real menus are stuffed into memory but never retrieved, and therefor using up more memory for no reason. (the only time it will be useful is when you put the exact same menu twice on 1 page AND use an identical menuProcessor for that).
  7. Christian Kuhn commented on patch set 4 11/03/22, 16:14

    Reply

    Well, we only found cases where empty menus kick in. We don't *know* if it's always like that. I could imagine this case: A menu is generated twice, with two different wraps (maybe one for mobile, one non-mobile?). In such a case, the runtime cache would kick in as well. Additionally, even *if* empty generation would be the only cache-hit case, we don't *know* until how expensive this creation is, so it may be useful even for empty stuff. As for memory: I doubt that's really relevant here. In the end, we're most likely talking about "not-that-much" html in ram. That should be ok. Since we don't know details here, the runtime cache is a safe bet, it will avoid performance-regressions we may have missed. As such, I still think that's a good way to go, at least for now. What do you think?
  8. Christian Kuhn commented on patch set 4 11/03/22, 16:26

    I mean ... I don't insist on this solution - it's rather conservative and does not risk performance regressions we may have missed, yet. Looking at generate() and it's sub method isItemState() it seems there are further runtime caches, for instance in sys_page->resolveShortcutPage() ... So we could of course also remove the cache layer entirely. Benni, what's your stake on this?
  9. Christian Kuhn commented on patch set 4 11/03/22, 16:27

    sorry, missed adding the comment to correct thread.

    Reply

    I mean ... I don't insist on this solution - it's rather conservative and does not risk performance regressions we may have missed, yet. Looking at generate() and it's sub method isItemState() it seems there are further runtime caches, for instance in sys_page->resolveShortcutPage() ... So we could of course also remove the cache layer entirely. Benni, what's your stake on this?

    Reply

    Done
  10. Benni Mack commented on patch set 4 11/03/22, 16:34

    commit message

    Reply

    The runtime cache with a few kb of the generated HTML should not be an issue IMHO. Looking at the bootstrap package the runtime cache will save a few things, will do some more perf tests by switching to runtime cache vs. null cache.
  11. Christian Kuhn uploaded patch set 5 11/04/22, 12:28

  12. Christian Kuhn commented on patch set 5 11/04/22, 12:45

    Reply

    Loek had a closer look at this: this cache-layer is per menu level. A menu with 3 levels generates 3 cache entries. We already saw that successful cache-reads seem to happen only when empty menus are calculated. This happens when for instance a third level is defined, but no pages are found. This calculation is quick, though. I'll thus change the patch again to remove the cache layer entirely now - it is completely useless.
    Numbers with patch set 5: Measuring bootstrap_package "pages/2-columns" with a reduced set of loaded extensions (only what is needed), optimized autolader no backend user logged in, bin/typo3 cache:flush, bin/typo3 cache:warmup, then blackfire on the page. about 10-30 ms less rendering time, most of that from queries. before: 859 calls to Statement execute after: 799 calls to Statement execute And that's on an empty 'cache_hash' table, so numbers will be higher when DB is remote, or when cache_hash is populated. Totally worth it.
  13. Christian Kuhn voted on patch set 5 V +1 CR +1 11/04/22, 12:45

  14. core-ci voted on patch set 5 V +1 11/04/22, 12:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33111

  15. Andreas Kienast commented on patch set 5 11/04/22, 12:55

    The commit subject should be something like "Drop ineffective TMENU caches" now, do you agree?
  16. Benni Mack updated the commit message in patch set 6 11/04/22, 13:01

  17. Oliver Klee commented on patch set 6 11/04/22, 13:04

    AbstractMenuContentObject.php:138

    If this is unused now, can we directly remove it? Or should we deprecate it to be removed in V13?
  18. Christian Kuhn commented on patch set 6 11/04/22, 13:06

    Reply

    Done

    AbstractMenuContentObject.php:138 Reply

    Keep it: I plan to deprecate the entire abstract in a divide&conquer patch since this gives us full freedom to refactor TMENU ;)
  19. Loek Hilgersom updated the commit message in patch set 7 11/04/22, 13:06

  20. Loek Hilgersom commented on patch set 7 V +1 CR +1 11/04/22, 13:07

    Reply

    It's much worse than that. One 3-level menu created 7 cache records in my test-site: 1 for the 1st level, 4 for each submenu, 1 for the one subpage that had sub-subpages, and the best: 1 empty array for all pages that have no subpages, the only record that is actively retrieved multiple times, ...(sigh)
  21. core-ci voted on patch set 6 V +1 11/04/22, 13:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33118

  22. core-ci voted on patch set 7 V +1 11/04/22, 13:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/33119

  23. Christian Kuhn voted on patch set 7 V +1 CR +1 11/04/22, 13:18

  24. Benni Mack voted on patch set 7 V +2 CR +2 11/04/22, 13:23

  25. Benni Mack merged patch set 8 11/04/22, 13:23