|
|
|
|
|
by enneff
5088 days ago
|
|
Go lets you pass around raw values without overhead. An int32 is 4 bytes. A struct { a, b int32 } is eight bytes. A [4]int32 is 16 bytes. A [4]struct{ a, b int32 } is 32 bytes. (I think you get the point :-) In Java all objects are passed by reference, which causes bloat and cache locality issues. Also there are bookkeeping costs associated with even trivial objects: a simple array carries around an additional 16 bytes of memory. Furthermore, the core Java libraries make it very difficult to write code that doesn't generate a lot of garbage. In fact, it's very difficult to write allocation-efficient code in Java without writing very unidiomatic Java code. These problems are worsened in more dynamic JVM-based languages like Scala and Clojure, which generate huge amounts of garbage due to runtime reflection. Here's an interesting discussion of these issues: http://loadcode.blogspot.com/2009/12/go-vs-java.html |
|
Scala is a statically typed language
Go may make more efficient use of memory for the cases you describe, but the JVM still beats the pants off Go:
http://shootout.alioth.debian.org/u64q/benchmark.php?test=al...
Also, you haven't factored in Java's escape analysis and on-stack allocation.