Passing array as const slows down code?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Fri May 4 09:07:20 PDT 2012


On 03/05/12 16:07, Steven Schveighoffer wrote:
> 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.

Yes, with the original post I was hoping there might be a quick answer that 
would avoid anyone having to go through the details of my code, e.g. a known 
issue or reason.  But I can confirm that the effect is real and consistent; I 
tested it again just now, and it even scales with the system size.

I've made some attempts to construct a minimal example, as opposed to my rather 
complicated code, but so far have been unable to reproduce the effect with a 
simple case. :-(  What I could do is try and cut away from the existing code and 
see where the effect vanishes, or prepare a set of single-file versions of the 
code with no qualifiers, const alone, and const ref respectively.

On 03/05/12 16:59, Artur Skawina wrote:
> 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.

I'm running GDC 4.6.3; I don't know if this fix made it into that release.  It 
would make sense if faulty inlining was responsible, though.


More information about the Digitalmars-d-learn mailing list