runtime vs compile-time ref safety: 20% overhead in my example

Martin Nowak code at dawg.eu
Sun May 26 13:23:45 PDT 2013


On 05/26/2013 06:12 AM, Timothee Cour wrote:
 > Which means that the extra check to make sure the output reference
 > doesn't escape a local incurs a 20% cost in my example.
 >
 > Is there a better implementation (i have a single pointer comparison
 > though so I'm not sure how that would be optimized) ?
 >
 > If not, it will mean user will have to choose between enabling runtime
 > safety checks (20% in my simple example), or throwing away ref safety by
 > disabling checkboundsref flag.
 >
If you look at the asm output and lower the iteration count, you'll see 
that you bench llvm's inliner rather than the cost of the runtime check.
Also the version that doesn't perform the bounds check doesn't use the 
ptr parameter, so the variable can be optimized away.
In a real implementation computing the frame pointer doesn't incur much 
cost, it is already available in a register or it is a constant offset 
from the stack pointer.
The branch is easily predictable, as the condition is always the same.



More information about the Digitalmars-d mailing list