Passing array as const slows down code?
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Fri May 4 09:26:56 PDT 2012
On 04/05/12 18:07, Joseph Rushton Wakeling wrote:
> 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.
Let me clarify that last statement. The core function in the struct is one that
does something like this (pseudocode):
auto myMainFunc(Rating[] x)
{
do {
myFunc1(x);
myFunc2(x);
myFunc3(x);
/* calculate exit-condition value*/
} while (/* conditions not met */)
return results;
}
So, if I'm putting in const (or const ref) qualifiers, they're being applied to
the inputs of myMainFunc, myFunc1, myFunc2 and myFunc3. These 3 are obvious
candidates for compiler inlining, so anything which affects the possibility of
this happening could be expected to hit performance.
(... in the real code, myMainFunc() is called reputation(); the 3 interior
functions are respectively userDivergence(), userReputation() and
objectReputation().)
More information about the Digitalmars-d-learn
mailing list