3 ms·
The big problem with laziness is that it becomes impossible to reason about performance, because performance becomes noncompositional. If y = g(x) then we expec
by lmm 7y ago
The big problem with laziness is that it becomes impossible to reason about performance, because performance becomes noncompositional. If y = g(x) then we expect the computation time of f(g(x)) to be the computation time of g(x) plus the computation time of f(y), but in the presence of laziness that's no longer true. Any sufficiently large codebase hits a performance problem (usually a trivial one that ought to be easily resolved) eventually, and at that point you lose the ability to refactor fearlessly that's the great advantage of Haskell-like languages.
- tome 7y agoHmm, I'm not sure that's quite right. The time taken by f(g(x)) under lazy evaluation is known to be no more than the time taken under strict evaluation. It's the space usage that can be hard to predict.
- reitzensteinm 7y agoIt's not more operations, but that extra space usage can mean the difference between creating and freeing objects with bump allocation in Eden that fits in cache, and walking over the heap doing a full GC so you don't run out of memory. There's a very real difference between what a simplified model of time complexity says should happen, and what actually happens when the layer of abstraction underlying the ivory tower start to spring a leak.
- lmm 7y ago> The time taken by f(g(x)) under lazy evaluation is known to be no more than the time taken under strict evaluation. True but irrelevant (particularly given that idiomatic Haskell involves a lot of constructions that would take infinite time under strict evaluation). If x < a, y < b, z < c and a + b = c, that doesn't give you any useful relationship between x, y and z.
- tome 7y agoA fair point. An example would be something like take 10 (map (+1) [1..])
- TheCoelacanth 7y agoI don't think that's true in practice because excessive memory usage can lead to slower execution.