The Web is Slow Because of Database Queries in Loops
functionwhatwhat.com
functionwhatwhat.com
I think that that's been a blessing and a curse because, damn it, a lot of "web developers" are still stumbling onto concepts that systems developers figured out in the 1970s.
Maybe it's just the perspective that comes with age, but even I know better than to re-establish a database connection every single loop iteration. Isn't this pretty basic stuff? I don't pretend for an instant to be an all-star coder, but surely people have progressed beyond what 16-year-old me could have recognized.
If it's as widespread as the author claims, aren't/shouldn't things like this be taught in your basic CS courses?
Its pretty much been covered in every introductory database book/course/etc. I've seen. The problem is that application developers (and this is by no means limited to web app developers, or application developers which in other domains have limited technical skills) often feel that they don't need to understand databases, and tutorials on application-side technologies that use databases often promote bad use of databases (and, often, ORMs go even further in making bad choices the path of least resistance.)
And when the ORM alone isn't enough to make an application performant? "Fuck these RDBMS, lets get a real database engine in here!"
The problem is developers of applications which rely on persistent data not feeling the need for a more than superficial understanding of the data storage technology they are using, which is a problem independent of programming paradigm or database paradigm or database language.
Actually, it is also useful these days to thing of whether work is done all in registers, all in L1 cache, all in L2 cache, all in RAM, all in disk cache(a form of RAM), all in disk interface cache(RAM on the hard drive controller), disk, or somewhere across a network connection which could be in the data center, across town, across the country or across the world.
It would be useful if training courses moved that big-O stuff off the the sidelines as a little historical note because it really is a theoretical analysis of algorithms, all things being equal. But in the real world, all things are NOT equal.
Similarly the issues around threading an locks on mutable state which can consume 50% or more of CPU time on a modern processer when an developer tries to roll their own multithreading. Immutable state and interthread queues are the only way to go, and the best way to do it is to explicitly design around the actor model.
Usually a combination of lazy-loading + loops, or doing things in python/ruby/etc that the SQL/whatever optimizer could have done much faster
There are so many things that could be pre-cached on most sites, and still, tools and frameworks often optimize for the use case of request -> query -> response.