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.
tb_megamenu_block_view() is taking 1500ms on a site I'm profiling.
Caching the value of #markup reduces this to 3ms.
Comment | File | Size | Author |
---|---|---|---|
#18 | tb_megamenu-fix_check_for_i18n_block_enabled-2370309-18-7.patch | 640 bytes | rossb89 |
#9 | tb-megamenu-fix-performance-2370309-9.patch | 622 bytes | btopro |
#4 | tb_megamenu_2370309.patch | 1.33 KB | catch |
#1 | tb_megamenu_2370309.patch | 1019 bytes | catch |
Comments
Comment #1
catchComment #2
Fabianx CreditAttribution: Fabianx commentedLooks great to me!
Comment #3
Fabianx CreditAttribution: Fabianx commentedI spoke too soon, we should probably use render caching instead with a #pre_render function.
The reason is that there can be role specific parts (as usual for menus), so DRUPAL_CACHE_PER_ROLE and also there is at a minimum i18n support via language needed, which drupal_render_cid_parts() will take care of.
Comment #4
catchHere it is with render caching and DRUPAL_CACHE_PER_ROLE.
Comment #5
Fabianx CreditAttribution: Fabianx commentedI think given that some of this could be PER_USER (in certain scenarios), we would need to either:
a) Add a variable to turn it off / on
b) Add an alter hook to change the cache_info before returning?
Or would hook_block_view_alter() be needed to be used for that?
Comment #6
lavesh bhandari CreditAttribution: lavesh bhandari commentedI have domain access enabled on my site. Would the mentioned patch #1 handle the caching with domain access enabled
Comment #7
gappleThis looks like it has a similar intent, but different approach from #2187927: Mega Menu Blocks don't cache
Comment #8
btopro CreditAttribution: btopro at Pennsylvania State University commentedPart of the issue is that module_enable is called. Uhh... why is this? This should really be module_exists and then a conditional if it does. Currently, if i18n_block doesn't exist on a site it'll sit here and churn every page load.
Even if it does exist... it'll still churn every page load off of this one call.
Comment #9
btopro CreditAttribution: btopro as a volunteer commentedYeah I'm thinking this is actually just a mistake now that I see it.
If you'd like profiling proof, this patch did this to a site I was debugging:
Prior to patch
Executed 519 queries in 189.28 ms. Queries exceeding 5 ms are highlighted. Page execution time was 1819.86 ms. Memory used at: devel_boot()=2.12 MB, devel_shutdown()=51.2 MB, PHP peak=53.75 MB.
AFTER FIXING TB_MEGAMENU
Executed 200 queries in 53.01 ms. Queries exceeding 5 ms are highlighted. Page execution time was 510.65 ms. Memory used at: devel_boot()=2.18 MB, devel_shutdown()=46.77 MB, PHP peak=48.25 MB.
uhhhhhhhhhhhhh.....
Comment #10
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedUh, yes ...
RTBC - Nice find, @btopro!
This is critical as its a module_enable call at runtime!
( I thought variable_set was the worst I would see at runtime for every request ...)
Comment #11
netw3rker CreditAttribution: netw3rker commentedJust goes to show, there's nothing new on the internet.. I just traced this & arrived to report it too :)
Thanks @Catch!
Comment #12
btopro CreditAttribution: btopro as a volunteer commentedok so can we get #9 in and speed up 9,500+ sites when they upgrade? :)
Comment #13
Aambro CreditAttribution: Aambro as a volunteer commentedI can't apply #4 against latest dev version.
If I apply it manually, I get no errors, but also no data where the block should be.
The function before patch now looks like this:
and this is how I applied the patch:
Any ideas?
Comment #14
netw3rker CreditAttribution: netw3rker commented@aambro are you referring to the right patch and the right issue here? this patch doesn't deal with 'fontawesome' at all...
Comment #15
HansKuiters CreditAttribution: HansKuiters commentedApplied patch #9 against 7.x-1.0-rc2 manually. Works fine. Thanks!
Comment #16
zaclittleberry CreditAttribution: zaclittleberry commentedApplied patch #9 manually against 7.x-1.0-rc1 works and reverts visible issues in megamenu as well. (module was frozen at rc1 in a testing environment when I discovered its update was an issue).
This is not only a performance issue, but also causes i18 to be enabled but not intended to be if it was installed, but not enabled already. This can happen in cases such as multi-site where the module is in all sites and needed for another site, but not the site tb_megamenu is enabled in. Or in the case of i18 module not being used, but still in the modules directory (poor code cleanup. it happens). In this case if the module is very out of date because it is not being updated as a disabled module, it is possible this bug could open a security risk.
This patch is very simple and straightforward and should be fast-tracked to a recommended release.
Comment #17
azinck CreditAttribution: azinck commentedJust piling on that this should get in ASAP.
Comment #18
rossb89 CreditAttribution: rossb89 at ComputerMinds commentedThis patch does indeed fix the big no no of
module_enable
, but I have found an issue where we shouldn't really be just checking if the module is enabled, we should be checking if i18_mode is actually enabled on this block.Just because the module is enabled does not mean that this block has had any translation specific settings applied to it.
I've discovered an issue where because the module is enabled, but the block in question does not necessarily have any translation settings applied to it (i18n_mode == 0), and because the block title comes is not set in the block->title but instead comes from views, available in
$block_content['subject']
we end up with no block title being set from this logic block:The patch i've written here checks against if we have actually got
$block->i18n_mode
enabled, then we can safely say that the block has i18n enabled settings, thus should have a block->title that will be set (for translation purposes).This will then solve the issue with block titles that are coming from views that are currently missing, just because the i18n_block module is enabled but not necessarily used on this block.
Comment #19
rossb89 CreditAttribution: rossb89 at ComputerMinds commentedComment #20
shefbel CreditAttribution: shefbel commentedI have faced with the same performance issues. And fixed it in the same way as suggested in
tb-megamenu-fix-performance-2370309-9.patch
Please add patches to main code branch. Current module state (tb_megamenu-7.x-1.0-rc2) is really frustrating.
Comment #21
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRTBC for #18, this needs to be fixed.
Comment #22
kobee CreditAttribution: kobee as a volunteer commentedRTBC for #18 too. Can be committed to the main branch .
Comment #23
mnico CreditAttribution: mnico at TIFON commentedThe patch from #18 works like a charm.
Comment #24
lathanYay finalllyyyyy found what was choking this module! TYVM for patch
Comment #25
sant3001 CreditAttribution: sant3001 commented#18 really needs to be pushed to the stable release. I didn't read this post before profiling the site and finding that module_enable was a HUGE issue in our website and I had to patch it for the site to go life. After applying the same patch as #9 our site speed was increased by 800%.
Comment #26
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI contacted the author of the module and asked to fix this issue and create a new stable release.
I hope they will react.
Comment #28
cgmonroe CreditAttribution: cgmonroe as a volunteer commented