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.

Comments

johnvb created an issue. See original summary.

lukasss’s picture

Status: Active » Needs work

I can confirm these problems.

lukasss’s picture

I 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.

lukasss’s picture

Version: 8.x-1.39 » 8.x-1.x-dev
Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new1.18 KB
lukasss’s picture

#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

nikkrop’s picture

#4 Working for me.

lukasss’s picture

Status: Needs review » Reviewed & tested by the community
lukasss’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.11 KB

change patch for fix #5

nikkrop’s picture

Status: Needs review » Reviewed & tested by the community

#8 Worked for me.

gnikolovski’s picture

Assigned: Unassigned » gnikolovski
gnikolovski’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

  • gnikolovski committed aff7d8d on 8.x-1.x authored by lukasss
    Issue #3145777 by lukasss, nikkrop, gnikolovski: Performance issues with...

Status: Fixed » Closed (fixed)

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

lukasss’s picture

StatusFileSize
new888 bytes

I m sorry!
Apologize... I fucked up...

My previous patch has terrible error.

nick hope’s picture

#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.

nick hope’s picture

#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?