Hunting Down Quadratic Loops in django CMS 0 ▲ Vinit Kumar 1 hour ago · 6 min read1214 words · Tech · hide · 0 comments 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… No comments yet. Log in to reply on the Fediverse. Comments will appear here.