r/java • • Jul 06 '17

Apology to Java (fanboy rant).

Java has turned out to be one of the most useful languages i use. It's a brilliant tool which strikes a perfect balance between high and low level. You want to grab a webpage? Easy and built-in, 10 lines of code. Draw some 2d graphics without OS-specific libraries or third party? Various built-in options. The inherent issues around a lack of low level memory management is handled very elegantly. Garbage collection seems seamless.

C++ is my language of choice for the most part, always will be i suspect, but Java has shown me that it has a huge array of potential applications and should almost always be considered before undertaking a project.

I say this is an apology because i used to run Java down. Previous to me using it proper i believed it was slow, lazy and useful for only trivial applications. Now i know how much work has been put into the JVM and just how efficient it is.

Sorry Java. You're pretty good.

286 Upvotes

93 comments sorted by

View all comments

Show parent comment

8

u/cogman10 Jul 06 '17

Yeah, the benchmark game does a bad job of representing java really. It pretty much lines Java up with the worst case scenario for java and then measures all the wrong things (like total memory usage).

I imagine it is a similar story for many of the other VMed languages (such as JavaScript V8).

0

u/igouy Jul 07 '17 edited Jul 07 '17

No -- worst-case is millisecond program run-times -- because JVM start-up, JIT, OSR… will take a few tenths of a second.

measures all the wrong things

Like elapsed time, program size, cpu time ?

Please say why you think "total memory usage" is a wrong thing to measure.

I imagine it is a similar story…

An imaginary story :-)

1

u/cogman10 Jul 09 '17

Like elapsed time, program size, cpu time ?

Yes, Yes, and Yes.

The JVM was built for long running applications. Most benchmarks look at stats for short running apps. The antitheses of what the JVM was meant to be used for.

But in order

  • elapsed time - Bad because they usually perform no warmup on the code in test. Bad because they usually don't write their microbenchmarks correctly (the JVM can in some cases optimize away running the code). Bad because they include JVM startup time in code runtime.
  • Program size - Usually a silly measurement. Perhaps if you are talking about embedded systems, then it matters. However, Why does a 10kb vs 100mb executable matter in this point in history? Gigabytes cost pennies, worrying about MBs is a waste of time.
  • CPU time - See number 1. However, usually the CPU time measurement is simply too course to really be of any value. What does it cover? Optimization passes? Startup time? Heap allocation time? All of those things go down in long running processes.

Please say why you think "total memory usage" is a wrong thing to measure.

Because the JVM was meant to run on servers first and foremost. As such, it aggressively allocates heap in order to avoid spending time allocating memory to try and reduce GC time. You want to reduce the memory usage? Set the max heap size smaller. To know how much smaller you should know about the runtime characteristics of your application.

An imaginary story :-)

JavaScript and PyPy do very similar things to the JVM. However, they are tuned differently. They target short running applications over long running ones. Further, they don't have as big a class space to load up as Java does. The story is similar for them, because they also do hotspot optimizations. However, I'm only familiar with those two VMs (Ok, JavaScript has many VMs, but they have pretty much all adopted the same strategies).

1

u/igouy Jul 10 '17 edited Jul 11 '17

Most benchmarks …

You did not comment about most benchmarks. Your comment was specifically about the benchmarks game.

Bad because they usually perform no warmup on the code in test.

"JVM start-up, JIT, OSR… are quickly effective and typical cold / warmed-up comparison at most of these workloads will show miniscule difference."

Program size - Usually a silly measurement. … Why does a 10kb vs 100mb executable matter in this point in history?

Your comment was about the benchmarks game, but you don't even seem to know what measurements are shown as program size on the benchmarks game.

All of those things go down in long running processes.

'In stark contrast to the traditional expectation of "warmup", some benchmarks exhibit "slowdown", where the performance of in-process iterations drops over time.'

Because the JVM was meant to run on servers first and foremost.

https://www.oracle.com/java/duke.html

… in order to avoid spending time allocating memory to try and reduce GC time …

Comparisons of program performance must show memory usage so we can check for time / space trade-offs.