0

I've been playing around with a simple raytracer in go that has been working pretty neatly so far. I'm using multiple goroutines to render different parts of the image, which then place their results into a shared film.

Against my expectations, my go code is still about 3 times slower than equivalent java code. Was that to be expected? Further, when inspecting the CPU-Usage in htop, I discovered that every core is only used to about 85%. Is that an issue with htop or is there a problem with my code? Here is the cpu profile of my application

I did set GOMAXPROCS as runtime.GOMAXPROCS(runtime.NumCPU()). The full code is on github.

panmari
  • 3,627
  • 3
  • 28
  • 48
  • 1
    Please post the go and java code –  Jun 24 '14 at 15:28
  • It may be possible that you are creating too much objects that need to be destroy later, or using append() a lot. Usage under 100% may indicate that the communication mechanism you are using between goroutines is not optimal. Are you using channels or you adapted the Java code to use shared memory and mutex? – siritinga Jun 24 '14 at 15:39
  • did you use the GOMAXPROCS ? – fabrizioM Jun 24 '14 at 15:40
  • In any case, I would not expect Go code to be noticeably faster than Java, but not much slower either. – siritinga Jun 24 '14 at 15:43
  • I did use GOMAXPROCS. I added a link to the repository. – panmari Jun 25 '14 at 14:55

1 Answers1

0

I would guess that garbage collector is the problem. Maybe you are making a lot of unnecessary allocations. By using runtime.ReadMemStats you can find out how much time garbage collector has been running.

If this is the case then you must find a way to reduce memory allocations. By using pools of objects for example. Look at sync.Pool. Also there are few useful links that you can find via Google that explain how to reduce memory allocation. Look at this one for example.

Marko Kevac
  • 2,902
  • 30
  • 47