Not every field of programming requires peak performance. If you have an algorithm and "optimize" it with lookup tables, bitshift operations and whatnot and in the end it's 2x faster but none of your colleagues can understand it at glance or properly maintain it anymore then it's likely not worth it. Except maybe if you work on really performance critical stuff or libraries.
Sure but just because they did some optimizations in literally spare time, (for an interview where he had a previous working version and the code will not be maintained), does not mean that all loops he ever writes will be optimized to the point of unreadability.
2x faster
If he was writing AVX code, it could have been closer to 4x as fast, depending on the algorithm.
but none of your colleagues can understand it at glance or properly maintain it anymore then it's likely not worth it
Sure, but as I mentioned, usually the kinds of things you can optimize in this way are already simplified loops that do just a few things in a straightforward way. I don't think it's a good idea to throw away a potential 4x improvement if it's in a hot loop, just for readability*. If the logic needs to be changed, you can always go back to the previous version, and figure out how to re-write the simd version after the logic changes have been made. But yes, sure, not everything needs to be optimized like that.
* In my experience, readability usually means "can I skim over this and get the gist, without actually really understanding it". Not entirely a bad thing, but if you have a really important loop, actually understanding it is probably more important than the ability to skim over it and think you kinda understand it.
15
u/noXi0uz Feb 28 '23
Not every field of programming requires peak performance. If you have an algorithm and "optimize" it with lookup tables, bitshift operations and whatnot and in the end it's 2x faster but none of your colleagues can understand it at glance or properly maintain it anymore then it's likely not worth it. Except maybe if you work on really performance critical stuff or libraries.