[Prev][Next][Index][Thread]

Re: Dylan performance



Rolf Wester <wester@ilt.fhg.de> writes:

> Is there any means to make the dylan code faster?

Yes. Your code is spending a lot of time doing generic function
dispatch and bounds checking.

In detail:

> define method temp (nx :: <integer>, ny :: <integer>, nt :: <integer>)
> 
>    let t1 = make(<array>, dimensions: #(300 , 300), fill: 0.0);
>    let t2 = make(<array>, dimensions: #(300 , 300), fill: 0.0);

You should choose a type of float, and limit the array to this type of
float. A good choice is <double-float>, since it has the same
performance as <single-float> (at least on PCs), but more
precision. Also, you shouldn't hard-code the array size, when you pass
the bounds to the function from outside. So this would look like:

  let t1 = make(limited(<array>, of: <double-float>), dimensions: list(nx, ny), fill: 0.0d0);
  let t2 = make(limited(<array>, of: <double-float>), dimensions: list(nx, ny), fill: 0.0d0);

>    for (k :: <integer> from 0 to nt - 1)

The type specification here is completely superfluous, you can leave
it away without any adverse effect.

>            aref(t2, i, j) := aref(t1, i, j) + 1.0 + 0.1 *

Is there any reason why you don't use the syntactic sugar for array
access here? I consider

t2[i, j] := t1[i, j] + 1.0d0 + ...

to be much more readable. Note that I specify the precision for the
floating point constant here. Now since I have declared t1 and t2 to
always return <double-float>s, and also declared the type of the
constant, the compiler can directly call the right method for all your
operators.

And through type inferencing the compiler can find out that the result
of all those operations is a double float as well, so the assignment
will not generate a type check.

>      format-out("%d \n", aref(t1, 150, 150));

This will not work, as t1 contains floats, and %d displays
integers. So you will get a type error. Use %= for anything unless
there are specific reasons not to.

Please try out these changes and let us know how they affect your
measurements.

Also, take a look at FO's Performance Highlighting feature.

Andreas




References: