On Sunday, 30 June 2013 at 10:21:12 UTC, TommiT wrote:
Perhaps an interesting observation about this is that while in
C++ const correctness literally never improves performance [1],
in D (if these optimizations were implemented) const
correctness could potentially increase performance considerably
(if there are expensive postblits). Thus, functions should take
arguments by const value rather than value, when the type of
the parameter is either templated or has postblit.
[1] Except with constant folding or when the compiler can put
const data to rommable memory and then share it with multiple
instances of the same program.
Precisely, although something that could improve performance even
more would be escape analysis. In this example, if the compiler
can prove that there are no global/parameter mutable references
to a given variable then it will be able to apply the
optimisation regardless of purity.