6 ms·
> Concern 5: Java is too slow/consumes too much memory It's sad that this is still a thing. Compared to more trendy languages like Python and Javascript, Java
by bloomthrowaway 8y ago
> Concern 5: Java is too slow/consumes too much memory
It's sad that this is still a thing. Compared to more trendy languages like Python and Javascript, Java is very light on memory. JS is known for being fairly fast and "light", but its actually 5-10x slower than Java and uses 5-10X more memory. And the whole "lightness" of it is a lie. Javascript's run-time is probably bigger and more complex than the JVM.
Java used to be painful, but there's a ton of tools that make it easy to use if you know where to find them. Some, like Lombok, get rid of a majority of the "cruft" by enhancing the language itself. Awesome Java is a treasure trove of useful stuff. https://github.com/akullpp/awesome-java https://github.com/akullpp/awesome-java
The combination of speed, flexibility, and robustness can't be found anywhere else, Although Go is slowly catching up.
- jxub 8y agoAlso, https://github.com/cxxr/better-java https://github.com/cxxr/better-java with recommendations for learning how to write modern Java.
- bloomthrowaway 8y agoNice! I think it may be slightly out of date though. For example, you don't need Tuples library if you use Apache commons because it has Tuple support. Also, Javaslang has been renamed Vavr. Still a solid article though
- kodablah 8y agoWhile the gist of that page is nice, there are many many flaws with it. I could enumerate them all, but suffice to say don't just take the author's word for using Optional parameters or always prefer Guava immutable collections or any of that. Much of it is wrong or at least debatable.
- base698 8y agoHmm. Just checked memory use on some services we run on Go, Node, and Java. I'm not part of the Java team but results: Go: 40M Node: 64M Java: 4GB Any Java service I've seen in production has similar numbers. Coupled with the incredible startup time it's hard for me to see why you'd pick it in 2018.
- levosmetalo 8y agoIf you tell your Java application server "here you have 4GB, use it as you wish" it will happily comply and trade memory for performance. In most of the cases it's just a matter of setting a few Java runtime startup parameters.
- sirk390 8y agoIt's disrespectful to take 4GB if you don't need it. This should never be the default...
- boobsbr 8y agoRead the comment again: > If you tell your Java application server "here you have 4GB, use it as you wish"
- bloomthrowaway 8y agoIt's the default because in any garbage collected language you can delay taking out the trash as long as you want... as long as you have memory. The most efficient thing to do is never run the collector at all. JS does frequent GC cycles because its unacceptable to let a webpage eat all the ram. Not sure why Go collects so frequently. Java's default IMO is the most reasonable of the three. If you have a server with 4gb the best choice is to let the garbage collector use all of it
- fastbmk 8y agoJVM uses as much memory as you allow. Use `-Xmx39m` to beat Golang.
- inglor 8y ago> but its actually 5-10x slower than Java and uses 5-10X more memory I am definitely against the "Java is slow" claims and think they are mostly rediculous but so is this claim. Saying "uses 5-10x more memory and 5-10x slower" goes against every benchmark I've ever run and my understanding. Mostly because JavaScript runs on several JITs (V8, JavaScriptCore, SpiderMonkey, Chakra) with different performance goals and characteristics and so does Java (which runs very differently with Art compared to HotSpot for example). Not to mention things like Graal :) Slowness isn't a property of the language it's a property of the runtime. Usually performance is dominated by things like the speed of the packages used and standard library and not even the compiler. There is no 5-10x factor _either way_ between JavaScript and Java VMs, not to mention you can run JavaScript on the Java VM anyway so that comparison doesn't hold in that regard either.
- bloomthrowaway 8y ago>Slowness isn't a property of the language it's a property of the runtime This is true to an extent, but look at the time and money poured into PHP and how slow it still is after all these years. Language design choices have a huge effect on how fast the runtime can be. In Javascript, objects are stored as a map of key->value pairs, and aren't strongly typed. This design requires more overhead for type checking and many optimizations used by strongly typed languages won't work. Even in toy benchmarks its clear that Java has a performance lead https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/javascript.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... . It's slower than java on every test. You don't see the memory difference because these toy benchmarks don't allocate much. Node/JS will always use more memory for storing objects, sometimes far more because it isn't strongly typed. In Java, an array of ints will use 32 bits * size plus some fixed bytes. In Javascript, each item in the array can use 2-3x the max "size" of the number, because the runtime can't figure out what type it should be.
- blub 8y agoOther benchmarks from the same group do show the memory usage and both node and Java are quite bad, as expected. Node is spectacularly bad at some, using 1.8 GB vs Java's 384M or C++'s 155M for example.
- amelius 8y agoHow efficiently does Java run when compiled to the browser platform? (e.g. WASM) (The browser is an important target these days, so imho this question must be addressed; besides, I want to be able to use the same code on the server as on the client; and sadly, the JVM isn't guaranteed to work in every browser).
- bloomthrowaway 8y agoI'm really excited for WASM, it should be nearly as fast as native code. Java and native code aren't far apart though, so I would say 1.5-2x faster generally
- amelius 8y agoOk, but I'm worried about the garbage collector, and if it can run concurrently without interrupting the program (as a native JVM would do it).
- bloomthrowaway 8y agoIt should be able to... Hopefully Go and Java will be some of the first GC languages to target WASM, and we'll find out :) . Personally I'm more worried about the size of the GC getting added to the binaries than how fast it is.
- pjmlp 8y agoAssemblyScript already does it, if I am not mistaken.
- jackpeterfletch 8y agoIf the Javascript garbage collecter can do it then I don't see why not.
- amelius 8y agoThe JS GC can run in native code, in a separate native thread with shared memory access, and it can use things like memory barrier instructions, which have no equivalent in WASM yet.