I found a simple go based raytracer and thought it would be nice to
test its performance. The implementation is said to be about 2 times
slower than the C++ version.
By actually using Pointers a little more I managed to increase
performance by 65 %. One more source of speed loss would be ( in a C
world ) the use of value types in vector functions. Hence vectors will
be copied into the function and the result will be copied out of it.
In C++, one would have some in-place functions as well that take
pointers to prevent excessive copying.
To my surprise, when using pointers in a dot-product function, the
performance _decreased_ by the factor of 2 ! To illustrate my change,
have a look at this diff:
http://gitorious.org/gotracer/gotracer/commit/3e8499814b6f66021025e457a6354c9d14e4a1c2
If the same function uses value types instead of pointers, its as fast
as before:
http://gitorious.org/gotracer/gotracer/commit/87211c6baec27b003a051b1a04034ad9f528d2cc
If you want to have a look at the source, please feel free to clone
the project on gitorious:
http://gitorious.org/gotracer/gotracer
The branch named
http://gitorious.org/gotracer/gotracer/commits/vector_with_pointers_slow
pinpoints the pointer issue, the branch
http://gitorious.org/gotracer/gotracer/commits/vector_with_values_fast
is the fix.
What do you think, is this supposed to be like that ? I know some high-
performance C++ code where vectors/Point3 are passed by reference/
pointer preferably to increase performance, hence I consider this to
be a language bug, possibly ?
Thanks for your opinion on this.