5 ms·
for most of the time, many performance considerations are invisible from the higher abstraction levels, so you can concentrate writing simple, elegant and maint
by userbinator 10y ago
for most of the time, many performance considerations are invisible from the higher abstraction levels, so you can concentrate writing simple, elegant and maintainable applications in Java, Scala, Kotlin or anything that runs on the JVM.
Funny statement, at least for Java. I don't know anyone who would say the majority of Java applications aren't huge, slow, memory-hogging beasts compared to equivalent native ones, and whose codebases are just as unoptimised for the perspective of the humans who have to work with them. That's mainly perception from when I briefly worked with Enterprise Java many years ago --- no one wrote "simple" or "elegant" Java applications, and stuffing as many design patterns and abstractions in as you could was considered "best practice".
There are certainly examples of simple and small Java applications (see https://en.wikipedia.org/wiki/Java_4K_Game_Programming_Contest https://en.wikipedia.org/wiki/Java_4K_Game_Programming_Conte... ), and I've written a few, but the overwhelming culture seems to be that of anti-optimisation and bureaucratic excess. In some sense, it's almost like working against or "challenging" the JVM's optimiser is the norm.
In my experience, a "simple, elegant" design --- which does not necessarily mean "highly abstract" --- tends to be very close to optimal anyway, with the compiler's optimiser doing the remaining work. That makes me wonder whether claiming a language/runtime/compiler has powerful optimisation abilities is actually a reflection of how much the typical source code in the language has to be "cleaned up" by the optimiser in order to be decently efficient.
Also, does anyone else notice the "Machine code" given for the JIT example is completely unrelated to either the Java or bytecode? It's 16-bit realmode --- I recognise the access to the 40h segment, it seems to be timing-related, and a bit of Googling finds that it's actually part of an old TSR clock utility (with unknown source):
http://assembly.happycodings.com/code24.html http://assembly.happycodings.com/code24.html
- bitmapbrother 10y agoAh, the Java is slow argument. When were you doing Enterprise Java? It must have been around the pre HotSpot years. As for applications that are huge, memory hogs, complex and non elegant, well, congratulations you just described the majority of enterprise applications.
- NotRustAgain 10y agohttps://benchmarksgame.alioth.debian.org/u64q/java.html https://benchmarksgame.alioth.debian.org/u64q/java.html Consistently twice as slow, with memory usage between 2 and 400(!) times larger. Java is slow and bloated compared to native. Your next argument will be something about how micro-benchmarks don't reflect reality for larger programs...
- bitmapbrother 10y agoAh, synthetic benchmarks. Are you really sure they're consistently twice as slow? Your link shows otherwise. mandelbrot 17% slower fannkuch-redux 34% slower fasta 38% slower fasta-redux 39% slower pidigits 44% slower So much for predicting my next argument.
- CherryPickMuch 10y agoHow come you left out these ones? spectral-norm 115% slower reverse-compliment 121% slower n-body 136% slower regex-dna 235% slower k-nucleotide 253% slower Cherry picking your data shows you're either dishonest or really lost in your denial.
- bitmapbrother 10y agoPerhaps you should read his reply more carefully next time. He said the benchmarks were "consistently 2x" as slow. He was wrong and the rest of the synthetic benchmarks you posted just corroborated my point. As for being dishonest, well, you're commenting from a newly minted temp account so it would seem you didn't have the courage/backbone to use your real one.
- userbinator 10y agoIt's interesting that the "gz" column, which reflects the amount of source code required, shows a very slight trend towards C being smaller, although there are big exceptions like regex-dna and reverse-complement. I'm not seeing the 400x more memory - there is a 40x though. But if you add up the columns for the programs that have both C and Java versions, you get this rough summary... secs KB gz Java 76.33 2004048 12775 C gcc 37.32 793652 11651 ...that Java is on average half as fast as C and uses 2.5x more memory, while requiring slightly more source code.
- pron 10y ago> I don't know anyone who would say the majority of Java applications aren't huge, slow, memory-hogging beasts compared to equivalent native ones, and whose codebases are just as unoptimised for the perspective of the humans who have to work with them. I would, and I've been developing in Java for over ten years now, after ten years of C/C++. I think that your complaints have nothing to do with Java, and much to do with a coding style that became popular in the '90s. You could see the very same in C++ applications back then, but then Java took over. The big enterprise applications of the '90s and '00s reflect the prevailing mindset of the time. Java applications written today don't look like that. > In my experience, a "simple, elegant" design --- which does not necessarily mean "highly abstract" --- tends to be very close to optimal anyway, with the compiler's optimiser doing the remaining work. That makes me wonder whether claiming a language/runtime/compiler has powerful optimisation abilities is actually a reflection of how much the typical source code in the language has to be "cleaned up" by the optimiser in order to be decently efficient. In that case I think your experience may be limited, or that you're unaware how big "the remaining work" may actually be, especially on modern hardware. HotSpot has proven extremely adept at running many different code styles very efficiently. HotSpot's next-gen compiler, Graal[1], is IMO the biggest breakthrough in compilation technology of the past decade. It runs Java faster than C2 (HotSpot's current compiler), Python faster than PyPy, and JS as fast as any other VM out there. It even has a C frontend, which, while not yet matching gcc, performs surprisingly well considering how little effort has been put into it. This kind of work can be very important, namely, the ability to optimize code across different languages. A recent paper[2] found that re-writing parts of SQLite in Python (!), instead of the original C, can result in a 3x (!) performance boost when running in an application, as application and DBMS code can be optimized as one unit. [1]: https://wiki.openjdk.java.net/display/Graal/Publications+and+Presentations https://wiki.openjdk.java.net/display/Graal/Publications+and... [2]: http://arxiv.org/abs/1512.03207 http://arxiv.org/abs/1512.03207
- Buttons840 10y agoThat paper says the actual benchmark was only 2.2% faster. What does the 3x speedup actually mean then?
- Alphasite_ 10y ago
- greydius 10y ago> I don't know anyone who would say the majority of Java applications aren't huge, slow, memory-hogging beasts This is really a matter of perspective. A typical enterprise application is running on a beafy multicore processor and spending most of its threads' cycles waiting for database IO. Also, it's not really a concern if your jar file is 100 MB when your machine has 256 GB of ram. From this perspective, the fact that an application can be quickly slapped together from the multitude of Java libraries and frameworks by a stackoverflow savvy junior developer far far outweighs the marginal performance benefits that could be gained from using a language that compiles to native code. The fact is that Hotspot has made the jvm perform "good enough" for this kind of domain. And keep in mind that many enterprise developers (at least in my experience) have never used a language besides Java, so this level of performance is normal to them.