Hacker News new | past | comments | ask | show | jobs | submit login

While this is a common view, there is no reason to believe it is true. There was a related discussion on the D mailing list.[1] Functional code can be as performant or even better than explicit loops. [2] According to Walter Bright, a properly optimized compiler should be able to produce faster code when you avoid loops. [3]

I realize that Fortran compilers have focused on optimizing traditional explicit loops and other imperative programming constructs. Nonetheless, I'd want to see benchmarks before concluding this is a lost cause.

And of course for a lot of code it is better to write correct code quickly than it is to spend a week cutting the running time of a function called twice from 1.2 seconds to 0.9 seconds.

[1] http://forum.dlang.org/post/mailman.4829.1434623275.7663.dig...

[2] http://forum.dlang.org/post/mailman.4901.1434779960.7663.dig...

[3] http://forum.dlang.org/post/mlvb40$1tdf$1@digitalmars.com




> I realize that Fortran compilers have focused on optimizing traditional explicit loops and other imperative programming constructs. Nonetheless, I'd want to see benchmarks before concluding this is a lost cause.

Fortran since f90 has had syntax for and encouraged array level operations rather than looping over arrays. Surely there has been work on improving the performance of vectorised operations?


Fortran has had lots of implicit loops to optimize since 1990, so, as long as the compiler can see to the bottom of the call (via cross-module inlining), it will do a great job.

Interestingly, Fred Chow and the SGI compiler/Open64/Path64 etc. optimizes implicit loops by expanding them into explicit ones, and then making sure that the regular optimizer does a great job on that.


> Interestingly, Fred Chow and the SGI compiler/Open64/Path64 etc. optimizes implicit loops by expanding them into explicit ones, and then making sure that the regular optimizer does a great job on that.

So does GFortran, FWIW. That being said, there is a lot of work to that is done before this lowering pass (as I'm sure you know, but for other readers who might not be as familiar with Fortran and compiler internals). In particular, the Fortran array expression semantics are that the RHS is evaluated before assigning to the LHS. So a simplistic approach would require allocating a temporary array every time. So there needs to be quite a lot of logic to handle various special cases in order to avoid the temporary arrays.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: