On Monday, 7 November 2016 at 16:48:55 UTC, John Colvin wrote:
Some people use ref for performance to prevent the copying that must occur when passing by value. I propose a small optimisation to make this unnecessary in a bunch of cases.

At the ABI level (no change in language semantics), if a given parameter would otherwise be copied and passed on the stack:
1) immutable parameters to all functions are passed by reference
2) const parameters to pure functions are passed by reference, if and only if all other parameters - including any implicit this parameter - contain no mutable references (otherwise "weakly" pure functions could modify the data we are now referring to instead of having copied, changing semantics).

If this is done, it should only apply to parameters larger than a certain size, say 2 words. Indirect memory access comes with its own cost that is often larger than that of copying.

Reply via email to