I hope we all know by now that Premature optimization is the root of all evil.
One side of that quote means by optimizing you are increasing complexity and complexity is evil. The other less known side is today's optimization might be meaningless tomorrow.
What I mean is we used to think that, "Floating-point operations are slow, therefore you should use integers since they are 100x faster! You must use integers even if it makes your code more complex!
That is completely false today. Today, modern processors actually do floating point operations faster than integer operations. Did you know that? I was surprised as well when I tested it in Java.
Also, what about addition and minus are much faster than multiplications or divide? False today (no difference)
Double is much slower than float! False (only half as slow, which is nothing)
A few other things that I think will be useless soon (if they are not already):
- Threads. Threads aren't commonly thought as an optimization, but it really is. It trades complexity for performance. I imagine a concurrent model of tomorrow where we don't explicitly deal with threads.
- Inlining functions, the runtime or compiler should be able to figure this out for you
- The final keyword in Java. Basically inlining variable references (but we'll still use it for protection, today I use it for both protection and performance)
- Buffered IO, the operating system or runtime should figure this out for you
- Object caching (and caching in general at many levels), it's not far fetched for the runtime to handle this
- Minimizing branch statements, a smarter compiler can remove branches for you
- Using arrays instead of Lists, a smarter runtime can just use arrays underneath
- Unraveling/reversing nested loops
- Replacing recursion with a for loop
- Minimizing object size to fit into cache or cache alignment issues. This is a big one. Its a hard problem to crack, but if the runtime could really figure out that really needs to be in cache, then we can finally not care about object size.
- Selecting the smallest data type that will work. Maybe in the future an integer is rangeless
- Scalability. This sounds like an odd one, but scalability is a performance issue in the end.
- newing/deleting memory (looking at you C++), Java already solved some of this, others just need to catch up. It can still be improved even more
- Using shift instead of * or /
- Avoiding the use of Exceptions
- Tuning Garbage collector
- Double buffering, I think Swing already does this by default
My main point in all this is to be careful with your optimizations and you really should code for clarity and not speed.
So my question is, what are some "optimizations" you are doing today that probably will be useless tomorrow?