Hi,
I’m not entirely sure if this is a bug. While building several pages in Bricks, I noticed a significant slowdown when adding a menu to the header. I have an eCommerce site built with Bricks hosted on a VPS with 4vCPU AMD EPYC 7303, 16GB RAM, and 160GB NVMe SSD. According to Code Profiler, Bricks takes 2.4 seconds to initialize.
Removing the menu (wp_menu
) speeds up the page by 0.6 seconds!
I installed New Relic and analyzed the page load process in detail. Here’s what I found:
Frontend::render_element
is executed 428 times, and Element_Container::render
is executed 290 times.
Timing Details from New Relic (note: New Relic slows down the site, so times are slightly higher):
Custom/get_header 3,19s
– Custom/wp_head 480ms
– Custom/do_action 2,71s
— Custom/Bricks\Element_Container::render 2,7s
---- Custom/Bricks\Element_Nav_Menu::render 2,65s
----- Custom/walk_nav_menu_tree 2,64s
----- Custom/Walker::display_element 1,66s
----- Custom/Bricks\Frontend::render_data 1,59s
------ Custom/Bricks\Element_Container::render 1,58s
------- Custom/Bricks\Frontend::render_element 314ms
------- Custom/Bricks\Frontend::render_element 517ms
------- Custom/Bricks\Frontend::render_element 454ms
------- Custom/Bricks\Frontend::render_element 280ms
----- Custom/Walker::display_element 0,428s
----- Custom/Walker::display_element 0,131s
----- Custom/Walker::display_element 0,065s
----- Custom/Walker::display_element 0,097s
----- Custom/Walker::display_element 0,259s
It seems that with menus, Custom/walk_nav_menu_tree
is triggered. For each first-level menu item, it calls Custom/Bricks\Element_Container::render
. Then, for second- and third-level menus and their child elements, it repeatedly executes:
Frontend::render_element
Element::init
This eventually reaches the link level, where it executes:
Element_Text_Link::render
Element::set_link_attributes
Element::maybe_set_aria_current
Helpers::maybe_set_aria_current_page
url_to_postid
_prime_post_caches
wp_get_object_terms
- Several others.