Raytracing speed again, this time with gdc.

Dave Dave_member at pathlink.com
Sat Nov 10 14:47:40 PST 2007


"downs" <default_357-line at yahoo.de> wrote in message 
news:fh0iem$2dhc$1 at digitalmars.com...
> Bill Baxter wrote:
>>
>> Could the difference be in part due to default initialization in D?
>> Maybe all your rays and vecs are getting initialized first to NaN and
>> then overwritten with the value you want, and that is slowing it down.
>>
>> You could try sticking some =void's in your structs, like so:
>>
>> struct Vec {
>>   double x=void, y=void, z=void;
>>   Vec opAdd(ref Vec other) { return Vec(x+other.x, y+other.y, 
>> z+other.z); }
>>   Vec opSub(ref Vec other) { return Vec(x-other.x, y-other.y, 
>> z-other.z); }
>>   Vec opMul(double a) { return Vec(x*a, y*a, z*a); }
>>   double dot(ref Vec other) { return x*other.x+y*other.y+z*other.z; }
>>   Vec unitise() { return opMul(1.0/dsqrt(dot(*this))); }
>> }
>>
>> struct Pair(T, U) { T first=void; U second=void; }
>> typedef Pair!(double, Vec) Hit;
>>
>> struct Ray { Vec orig=void, dir=void; }
>>
>>
>> --bb
>
> If you check the source, you'll see that practically all my structs are 
> either
> manually initialized with proper values or the result of a calculation. 
> Also,
> I tried that and it's not it.
> Sorry.
>
> Still, thanks for the idea!
> --downs

Sorry if this has already been discussed, but if not: Have you checked to
see if function inlining differences are the culprit? The D front-end
doesn't inline functions with byref params, and for DMD at least the FE is
responsible for all inlining.

For GDC the front-end inlining might be turned off anyhow (I can't
remember), and maybe GCC does all that in the intermediate or backend
stages.. If so it would presumably be pretty close to the same for D and C++
but it might be worth a look anyhow.



More information about the Digitalmars-d-learn mailing list