Hunting Down Quadratic Loops in django CMS 0 ▲ Vinit Kumar 45 days ago · 6 min read1214 words · Tech · hide · Fediverse post Last week I merged PR #8913 into django CMS core. In a local, uncached benchmark, it took a permission-heavy menu on a 4,000-page site from 11.7 seconds to 105 ms. The fixes removed repeated work hidden in ordinary list operations, a pattern I’ve seen in almost every codebase I’ve worked on. The problem: loops inside loops Building a menu tree, applying menu modifiers, downcasting plugins, and checking page permissions all touch many objects at once. The modifiers handle soft roots, navigation extenders, and visibility filtering. Across these paths, I found loops that repeatedly scanned or copied a growing list. The inner loop rarely looked like a nested for. It was hidden in one of these three operations. 1. sum(lists, []) to flatten # Before def get_descendants(self): return sum([child.get_descendants() for child in self.children], []) sum with a list as the start value repeatedly evaluates acc + next_list. Each + copies everything collected so far. When joining 800 one-element… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town