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

Mr. Anonymous mailnew4ster at gmail.com
Sun May 26 13:31:39 PDT 2013


On Sunday, 26 May 2013 at 20:23:45 UTC, Martin Nowak wrote:
> 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.

I think the solution proposed in the DIP is worth checking, not 
solely due to performance reasons, but mainly for better safety.
A runtime check cannot check all possible code paths when 
testing, and an undetected bug can surprise you when you don't 
expect it.


More information about the Digitalmars-d mailing list