3 ms·
Sorry, but it is very uncommon for Java to use 10-100x as much memory. Those benchmarks are pretty irrelevant because all the algorithms in there are short-liv
by bad_user 17y ago
Sorry, but it is very uncommon for Java to use 10-100x as much memory.
Those benchmarks are pretty irrelevant because all the algorithms in there are short-lived.
As far as I know CPython uses reference-counting for GC. And while this has definite advantages, this creates the potential for memory-leaks when using cyclic data structures. Also, the heap can get pretty fragmented, which for long-running processes can leave the heap looking like swiss cheese.
This doesn't happen with Java, but as a side effect a compacting GC usually allocates twice the heap size needed since it needs space to defragment the heap. The JVM's GC is also a Generational GC, separating generations in multiple regions, such that short-lived objects can be collected faster and newer objects can be allocated faster with speeds comparable to a stack allocation.
On Python, reference counting has the advantage of being cache-friendly and pretty deterministic. And when it comes to web servers that fork processes for requests, this is alleviated by the fact that the Python process has a short life.
On memory consumption, yes, Java might have the heap doubled, and the garbage collection is more non-deterministic. But it depends on your application ... the JVM ends up using memory a lot more efficiently for long-running processes, although the upfront cost is higher.
- igouy 17y ago> Those benchmarks are pretty irrelevant because all the algorithms in there are short-lived. Did you dismiss them without checking if any in fact did show Java using 10-100x more memory? You do seem to have dismissed them without asking yourself if they demonstrate the point you wish to make. The obvious example would be binary-trees which mostly allocates and deallocates binary trees - Java 6 -server #2 = 289,920 KB Python CPython #6 = 674,488 KB http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=java&lang2=python&box=1#measurements http://shootout.alioth.debian.org/u32q/benchmark.php?test=al... And if the Java program loops for 15 minutes - Java 6 -server #2 = 855,996 KB http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=javasteady&lang2=python&box=1#measurements http://shootout.alioth.debian.org/u32q/benchmark.php?test=al... Does that look like 10-100x as much memory?
- bad_user 17y agoYes, sorry, I didn't bother to look at those results.