Optimizing Everything To Instant*
So here’s a wacky idea on how Rails, Perl, Python, and everything else can be optimized to be so fast as it’d be almost instant. Bear with me here….
- First, you find some code, a framework, a program, whatever it is you’re into, and find a benchmark or test suite you can run on it.
- Next, grab some sort of code metrics suite that can record the time it takes for your test suite to run through it. Something like metric_fu, the built in benchmark module, New Relic RPM, or some other performance test system.
- Run the benchmark and review the code metrics. You will probably see a few “hot spots” where certain functions or operations take longer than others.
- Here’s the tricky part, but in the grand scheme of things, just a minor detail. Optimize the function, or the bit of the function that’s causing issues. This could take a short time (unused code, recursive loops, something like that) or a long time (refactor, iterate, rinse, repeat).
- Now run the benchmark again, find the next hotspot, and repeat the process until no more hotspots are found.
- Now the code will run instantly, as you have optimized it down to zero. Taking this method to it’s completely logical conclusion you could run another benchmark and find the next set of hotspots, or run it against the next module or part of the framework until you’ve optimized it all down to zero.
Congratulations, now Rails requests (obviously taking things like network latency into account, until you turn your now optimized optimizing brain to that problem) all run in 0.0 seconds. You won!
* Ok, so obviously (I hope) this is a post that is in jest, as at some point you will run up against issues that can’t be optimized, either because of latency you can’t avoid from disk loading, more database indexes vs loading from disk, the laws of physics, code complexity vs readability, etc. It is however something though that I hope gave you a bit of a giggle (that’s maybe a stretch I admit) or a slight pause to think that maybe, just maybe this could (in some fashion) work for you for some situation.