Groovy 64bit Memory Consumption
Why is it that Groovy (version 1.8.0) uses so much more memory in 64bit mode? As far as I can understand yes 64bit uses larger pointers and can take up to twice the memory sometimes but Groovy can take up to 2000% more memory in 64bit mode compared to 32bit.
Just a simple test I have below might explain something. This test (code below) is not intended as a speed benchmark but just to get an example of memory usage in Groovy on different JVM setups.
When running the below code, compiled and run with java.exe and not groovy.exe, it uses 17MB of memory. When running the exact same code on the 64bit JVM it consumes 430MB of memory and even with CompressedOops it uses well over 300MB.
Just a quick comparison to Java, though I do still expect Groovy to use a little more memory than native Java. The same code just modified to pure Java takes 8MB memory in 64bit mode and 4MB in 32bit mode.
Is there a bug in Groovy? Or am I missing something?
class MemoryTest {
static main(args) {
double result = 0.00
long startTime = System.currentTimeMillis()
long endTime = System.currentTimeMillis()
for (warmup in 1..5) {
result = 0.00
startTime = System.currentTimeMillis()
for (i in 1..1000000) {
result += (34.673*i)/(Math.sq开发者_运维问答rt(31.92**42.42))
}
endTime = System.currentTimeMillis()
}
println "Result: ${result}"
println "Time taken: ${(endTime-startTime)/1000}"
}
}
Looks like the 64bit JVM just tends to use the maximum allowed heap before doing much GC work. This could be because until recently most 64 bit systems were servers and this behaviour is more appropriate for server systems. The default maximum heap size is also larger on 64 bit systems.
精彩评论