question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimize menu rendering performance for very large page trees (>10k pages)

See original GitHub issue

Currently django-cms menu rendering does not perform very well with large (>10k) page trees.

With 10k pages initial menu loading from db and saving it to cache takes about 5.7s. So whenever the cache is not populated or needs to be invalidated, 5.7s is added to the request.

The following measurements were done with django-cms 3.4.1 and a fresh, empty cache:

cache type page count size in cache [bytes] initial load [s] cache.get() [s] copy.deepcopy() [s] apply_modifiers() [s]
redis, local 10569 632840 5.753401 0.187351 0.967989 0.093391
redis, local 378 21157 0.373353 0.006281 0.022317 0.003631

MenuRenderer.get_nodes() is called for every occurance of the show_menu templatetag in the template. Before calling copy.deepcopy(nodes) the node list is always gotten from cache with cache.get() or built from scratch. Currently the same built menu tree is fetched from cache multiple times in the same request. copy.deepcopy(nodes) seems redundant, because the node list is a fresh one from cache every time anyway. My first impulse was to additionally cache the nodes on the request, so we don’t have to fetch from cache multiple times per request. In that scenario copy.deepcopy(nodes) makes sense. But as the numbers above indicate it is actually faster to fetch from cache than deepcopying. Even for small trees.

To further optimise for large page trees, it would be great to find a way to avoid needing the whole pagetree. So have it be smart about only fetching the required pages from the database for a specific show_menu tag. This will have its caveats and incompatibilities, because menu modifiers expect to get the whole tree to modify. And cms is just one of multiple sources for nodes.

With czpython/feature/menu-spped-enhancements we’ve already seen page load times for the draft mode going down from 12s to 3s on a site with 10k pages.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jriefcommented, Nov 20, 2019

I can confirm @stefanfoulis’s observation. In my case I have ~93k pages with that many tree nodes. Building the node-tree is way too slow: ~8 seconds. I’m currently looking for ways to partially invalidate the cache.

@evildmp

when we are using soft roots, a very sensible way for menu modifiers to behave is to work on only the cut tree that is needed

this is true for the menu modifier, but every time someone changes the visibility of a menu node and publishes that page, the whole cache is invalidated. This results in rebuilding the menu tree and saving it back to the cache – and that takes a lot of time.

0reactions
stale[bot]commented, Jul 28, 2022

This will now be closed due to inactivity, but feel free to reopen it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid an excessive DOM size - Chrome Developers
A large DOM tree can slow down your page performance in multiple ways: Network efficiency and load performance. A large DOM tree often ......
Read more >
How to solve the "Avoid an excessive DOM size" warning
A large DOM size negatively affects site performance and increases the page load time. You should take steps to simplify your HTML page...
Read more >
Rendering large lists in React: 5 methods with examples
Explore five methods for easily rendering large lists in React, including pagination, infinite scroll, and several libraries.
Read more >
Performance Optimization | Adobe Experience Manager
A performance optimization methodology for AEM projects can be summed up ... renders the page, or you can use the same script for...
Read more >
Best Practices for Speeding Up Your Web Site
The Exceptional Performance team has identified a number of best practices for making web pages fast.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found