4 ms·
Compiler optimizers are full of surprises going both ways: good and bad. And details like this can probably change from version to version and get affected by c
by dpc_pw 6y ago
Compiler optimizers are full of surprises going both ways: good and bad. And details like this can probably change from version to version and get affected by compiling options. I would also expect that performance is higher priority than code size, generally, so missed opportunities like this might go unnoticed and unaddressed a long time if they don't show up on performance benchmarks.
- eru 6y agoThe classic example of surprising optimization is perhaps matrix multiplication in Fortran: At some point in history, when you wrote the straightforward, primitive three-nested-loops version of matrix multiplication your code ran much faster than when you tried to implement one of the more sophisticated algorithms. That was because the Fortran compiler recognised the primitive version and replaced it with a special purpose highly optimized matrix multiplication. The compiler couldn't do that with the more sophisticated approaches.
- mmarx 6y ago> The classic example of surprising optimization is perhaps matrix multiplication in Fortran: > At some point in history, when you wrote the straightforward, primitive three-nested-loops version of matrix multiplication your code ran much faster than when you tried to implement one of the more sophisticated algorithms. It might also have been due to Fortran using column-major matrix layout; if you try to implement a sophisticated multiplication algorithm that is optimised for row-major matrices, then that will be slower (indeed, also the row-major three-nested-loops version is already quite a bit slower). Another thing is that the sophisticated algorithms usually have some constant overhead that makes them shine only on sufficiently large matrices.