Passing array as const slows down code?

Artur Skawina art.08.09 at gmail.com
Thu May 3 07:59:37 PDT 2012


On 05/03/12 16:07, Steven Schveighoffer wrote:
> On Wed, 02 May 2012 16:05:13 -0400, Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> wrote:
> 
>> On 30/04/12 16:03, Steven Schveighoffer wrote:
>>> Try removing the ref and see if it goes back. That usage of ref should not
>>> affect anything (if anything it should be slower, since it's an extra level of
>>> indirection).
>>
>> Removing the ref ups the time as described before, but only with GDC (DMD the runtime is the same).  It's a real effect.
> 
> I'm not familiar with GDC, but as bearophile says, it sounds like a compiler bug.  Maybe GDC is making an optimization in one case and not in the other, but both should be equivalently able to get the optimization.
> 
>>
>>> There is no implicit local copy for const. I have a suspicion that you changed
>>> two things and forgot about one of them when running your tests.
>>
>> Really don't think so.  You can even check the version history of changes if you like!
> 
> IIRC, your original post concerned not-checked in code.  Anyway, if you've re-run the tests, this is a confirmation.  I'd go ahead and file a bug against GDC.  Rest assured, const should not *slow down* anything.

There *was* a GDC bug some time ago, where a 'const' or 'in' function argument
prevented inlining. Iain fixed it, so unless an old GDC version is used, it's
probably not related.

http://forum.dlang.org/thread/jdhb57$10vf$1@digitalmars.com?page=16#post-mailman.33.1325763631.16222.d.gnu:40puremagic.com

artur


More information about the Digitalmars-d-learn mailing list