kidoman / rays

Ray tracing based language benchmarks
https://kidoman.com/programming/go-getter.html
95 stars 23 forks source link

Java: Further cleanup of calculation. Correct image size from 512 to 768. #13

Closed tkalbitz closed 10 years ago

tkalbitz commented 10 years ago

The code is much more readable and the image size is corrected. The new string fits in the image. Still a problem is the creation of garbage in the calculation. A first attempt which unrolls the vector operations looks promising.

tkalbitz commented 10 years ago

The problem is the garbage which is produced. Every call to a vector function produces a new vector instance. This is necessary because they are immutable. In C or C++ this instances are auto variables which are created on the stack. This temporary objects are directly cleaned when the variable gets out of scope by bumping the stack pointer around In Java this variables are created on the heap. There is a lot garbage produced in this hot loop. How is the behavior in Go?

With this changeset the garbage is minimized (spilling of new vector instances on the heap) and the float variables are create on the stack. A second possibility would be a mutable vector class version. The time on my machine for a 2048x2048 image is 76s (C++) and 95s (Java).

I will take a look for another workaround.

kidoman commented 10 years ago

In Go, they are also created on the stack (unless I am totally mistaken)