3 ms·
The thing is, so much was static. It's easy to shuffle bytes. There are a few problems: People don't know or care about profiling the basic stuff like context
by vidarh 12y ago
The thing is, so much was static. It's easy to shuffle bytes.
There are a few problems: People don't know or care about profiling the basic stuff like context switches and data copies; people don't have a baseline idea of what should be possible; abstractions upon abstractions upon abstractions even when it complicates the code.
One of my biggest pet peeves in that respect is that people tend to not even know how many objects they create in many dynamic languages. Many people don't even know of any simple ways of finding out.
My most successful application speedup (EDIT: measured in speedup per hour expended - plenty of examples of much greater speedups, but they are rarely as quick) was spending an afternoon eliminating string copies in a late 90's CMS written in C++, and cutting page generation time by 30% in a system that was already heavily optimized (it provided a statically typed C++ like scripting language that was bytecode compiled at a time when most competing solutions were using horribly inefficient interpreters, and were often themselves written in slow intepreted languages).
My second biggest pet peeve is when people think system calls are cheap because they look like function calls. Sometimes you can increase throughput by an order of magnitude just by eliminating small read()'s (non-blocking filling of userspace buffer instead, and "read" from that). When I see slow throughput, the first thing I do is break out "strace" to look for unnecessary system calls...
But these problems are often a direct result of abstractions that means huge numbers of developers don't know or understand the cost of a lot of the functionality they depend on any more, and can get away with that "too often" because they work on hardware that is so fast it is extremely forgiving (e.g. my new "weird unknown Chinese brand" 8-core phone does about 10 times as many instructions per second as my ISPs total computing capacity in 1995, and it's nowhere near the peak performance of todays flagship phones), ignoring the fact that at "web scale", things are not as forgiving any more: server costs quickly start adding up.
But of course, most of us most of the time work on stuff that needs to handle little enough traffic that paying an extra $20k for hardware is cheaper than spending the developer time to optimize this stuff. Ironically this makes the optimization more expensive: Fewer developers ever get to obtain the experience to optimize this stuff at scale.
- bane 12y ago>My most successful application speedup ever... > people tend to not even know how many objects they create in many dynamic languages One of my biggest speedup success stories was an internal inventory reporting tool for a large-ish online retailer. The code was written in Perl, with huge amounts of data aggregation happening in memory and using loads of Perl hashes pointing to other Perl hashes point to others (and turtles all the way down). On small subsets of the data, it would run for 4 or 5 hours then spit out some graphs -- this was acceptable performance for daily reports. But as the site grew, it started taking 8 hours, then 10 hours and then finally crashing when the system simply ran out of memory. So I did a simple conversion, all the hashes pointing to hashes etc. into arrays pointing to arrays. Pretty simple in the code, only a few lines of code here and there and a couple functions to map hash keys into array indexes. The next day the entire inventory system did a run (with this one change) and finished in 10 minutes and AFAIK they still use that same system even though the site and user activity has grown a hundredfold. The developer (self-taught) of the original code asked why this worked. I walked him through the big-O complexity of arrays vs. hashes, and more importantly the amount of stuff the hash type was dragging around through memory. There used to be a fantastic site with visualizations of all the perl datatypes and we sat down and started counting bytes until he understood the difference.
- dylanrw 12y agoIt's excellent that you'd do that for him, and he was curious/receptive enough to ask and step through it all. So many times I've seen people stay ignorant to save face.
- bane 12y agoHe's a great guy, really open minded and always learning. He taught me tons also, and he's moved far beyond where I could ever hope to technically.
- vidarh 12y agoI catch myself just throwing everything in inappropriate data structures myself these days, because the hardware lets me get away with it, and many recent languages makes hashes so ridiculously simple to work with and don't provide much more than that + arrays. I don't like it, though.
- bane 12y agoI guess that's kind of the problem though right? The hardware lets you get away with it, only until it doesn't. Then if you don't know the fundamentals, you're in trouble or you end up spending an inordinate amount of time and money trying to spread the task across dozens of systems in a couple racks of in some datawarehouse somewhere.
- frik 12y agoWe used a single 500 MHz web server at the ReactOS.org project and it handled the slashdot/reddit effect til ~2008. Slashdot.org was the 8 biggest website in the world back in 2005 (Alexa ranking). I coded a novel CMS in PHP that generated hundreds of static pages in 2-3 seconds. Our open source project team as well as dozens of translators (27 languages) used the RosCMS ajax-based interface to edit the content. Back then ajax was little known and GMail used iFrames instead of ajax. PHP based MediaWiki, phpBB, bugzilla also run on the same server, and all used our central logon system. That's the old version of the website: http://old.reactos.org http://old.reactos.org On a recent project my social website served thousands of concurrent requests on a notebook class hardware with a single CPU. It uses nginx and HHVM (Facebook's PHP JIT VM). And @vidarth is right that people usually don't know how many objects they create. But if you tend to care about speed you better should be careful. The same goes for database access, raw optimised SQL with good indexes fly.
- bane 12y ago> I coded a novel CMS in PHP that generated hundreds of static pages in 2-3 seconds. heh...that's fast enough to basically generate an entire site on demand (per user-click) on modern hardware. Why bother dynamically generate a single page when you can dynamically generate an entire site for a user? Now instead of serving thousands of requests per second, you can serve in the low hundreds and be just like any other modern framework! Next step! Hadoop clusters and web scale infrastructure consuming hundreds of kilowatts so you can serve high hundred concurrent requests per second. But now you have a scalability problem. Better bring in an entire team to solve this.