These idioms have a complete disregard towards performance.
These idioms have a complete disregard towards performance.
I do agree with your general point, though. I remember a one-line change in a Haskell function that led to a 10x increase in performance:
VeryLargeList.Select(x => x.Blah).ToArray()
And people are wondering why they get OutOfMemoryException.Before linq, people would just loop, and the array would not have to be allocated dynamically.
All I am saying is "more abstraction may lead to performace issue, and people should be aware of it"
Another example, when you do this:
SuperLargeList.Where(x => x.Blah).ToArray()
There is no way for the compiler to know whether the output array will have a small size or a large size, and so it will choose one or the other assumption (dynamic vs fixed allocation). The language chooses for you how it implements things, and this is all fine as long as you know about it, and as long as you can do something about it in the case when you need to optimize.So what, we should write everything as CPU microops? A good developer should be capable of looking at that level, sure, but it shouldn't be the default; most of the time the computer is better at judging these questions than the developer.
If you write a module with no regard for performance, because automatic profiling is still "in the green", you will spend your entire time budget (milliseconds-per-frame, milliseconds-per-request, milliseconds-per-megabyte, etc.) in the first half of your project and slowly realize that it's getting harder and harder to add new features without going into orange or even red territory. Sure, you can shave off 10% or 20% in "quick wins" with a bit of profiling, but nothing short of a rewrite can save you from inefficiency by a thousand cuts.
This doesn't matter if the module is not performance-critical, obviously. But when it is, then you should either plan for performance from the very start, or plan for a rewrite.
As they should. "Premature optimization is the root of all evil".
The 'summarized' catch-phrase always bothers me; the choice between optimized code and inefficient code is always clear to me.
http://delivery.acm.org/10.1145/370000/361612/a1974-knuth.pd...
"The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming."