I've a taxonomy containing just over 1000 terms, at most 5 levels deep but mostly 2-3 levels. When I add a hierarchical taxonomy menu to the home page performance deteriorates significantly to the point the site becomes almost unusable. I've since moved the block onto a separate test page instead of the home page so I can test performance without breaking the site.
I've set the Cache config option to Permanent and I've added some calls to \Drupal::logger to time the build() function in the block. It takes 3-4 seconds which isn't fantastic but I had hoped the caching would take care of it. However after experimentation I've discovered that the build() function get's called again each time a new user hits the page, as if the logging is using the user ID as a context. The context is set to `url.path` in the code which means the hierarchy will rebuild on every page it appears on even though it's identical. So I'm not sure why `url.path` is set in the cache context for the block - is this necessary?
Having put the logging in, I've noticed something more concerning. Even when the build function is not called (i.e. the cache is hit), the page still takes ten or more seconds to load. Removing the block from the page does restore the performance. So, it seems that even when retrieving the cached copy of the block data, some code is still using lots of CPU cycles. I wonder if this is related to rendering the output in the Twig template, but if so I'm surprised this isn't also cached.
Any assistance would be much appreciated.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 3145777--14.patch | 888 bytes | lukasss |
Comments
Comment #2
lukasss commentedI can confirm these problems.
Comment #3
lukasss commentedI think the context 'url.path' is needed for the "Dynamic Base term" function to work properly, but it definitely needs some work.
Also I noticed that here:
https://git.drupalcode.org/project/hierarchical_taxonomy_menu/-/blob/8.x...
the whole tree is always loaded, the 'max_depth' parameter is not used. 'max_depth' is used only in twig, which also slows down the gas loading when the cache is first build.
Comment #4
lukasss commentedComment #5
lukasss commented#4 solves context problems but not this
https://git.drupalcode.org/project/hierarchical_taxonomy_menu/-/blob/8.x...
I think this needs a change too
Comment #6
nikkrop commented#4 Working for me.
Comment #7
lukasss commentedComment #8
lukasss commentedchange patch for fix #5
Comment #9
nikkrop commented#8 Worked for me.
Comment #10
gnikolovskiComment #11
gnikolovskiThanks!
Comment #14
lukasss commentedI m sorry!
Apologize... I fucked up...
My previous patch has terrible error.
Comment #15
nick hope commented#14 applies cleanly to the latest 8.x-1.x-dev c23d6d1 (i.e. over the previous patch #8 and not instead of it) and I am not getting any errors (D9.1.10). Thank you.
I'm not sure about the performance because my taxonomies are large but not huge. If anything it feels a little slower than 8.1.42 at first, but I assume the benefit will be later, after caching takes effect.
Comment #16
nick hope commented#14 applies cleanly to 2.0.0-alpha1 and the menu still works.
Maintainers, can this please be re-opened as a normal priority task against 2.0.x-dev? The patch in #14 is from the same author, @lukasss, as the patch #8 that was committed, and he thought there was a "terrible error" with the committed patch. Should be at least considered?