3 ms·
I saw this tons back then, too. Even back in the paleo-web you’d see people writing nested for loops, sometimes obscured by functions or a class structure but s
by acdha 4y ago
I saw this tons back then, too. Even back in the paleo-web you’d see people writing nested for loops, sometimes obscured by functions or a class structure but sometimes just the adjacent HTML.
As you noted, this is one of the reasons why client-side JavaScript often falls far short of the envisioned benefits. In both cases, however, I would suggest that while the trend is real and should inform your architecture the most important thing is to routinely use your monitoring. Different apps have different performance challenges but they all need to be observable and I’ve seen so many times where people wasted tons of time and resources shooting in the dark because they didn’t have granular monitoring or thought it was too hard.
One of the best example I had was a while back when I inherited a Django codebase which was too slow. One of the developers had spent a couple days rewriting everything in Jinja2 because “Django is slow”, introducing the bugs you’d expect and leading to lots of new custom code to maintain (such as 3 versions of the human size formatting function). Performance didn’t budge. Six months later, I saw the MySQL query counter spiraling up on every page view, installed Django Debug Toolbar, looked at the queries, and spent an afternoon reverting all of the templates and fixing the N+1 queries which had always been the problem. That was tens of thousands of lines of code churn all wasted for what was eventually maybe 50 lines changed against the original codebase.
One thing I introduced which worked well was a test hook which failed based on the query counts for a view. That caught most N+1 issues and is conveniently easy to implement with almost any model.
- mireq2 4y agoI spent couple days rewriting everything from Django to Jinja2 and it was really big difference with 10x speedup (from 500ms for invoice list to 50ms). It was big e-commerce system with every ORM query optimized, selecting only required fields, prefetching related relations or selecting related. Django templates are really really slow and hard to debug. Rewrite was really great decision in this case.
- acdha 4y agoI’ve never seen a difference that pronounced (I’m guessing that you had a lot of template logic?) but that sounds like you did it the right way: based on profiling.