Comment by pron

5 days ago

And Java has some advantages that are hard to beat. It performs better than Go and builds just as fast (at least when not using some popular build tools) while offering unmatched deep, low-overhead observability.

People might think they may enjoy another language more, but the portion of people who eventually come to regret choosing Java is probably lower than that of any other language.

> It performs better than Go

Do you have some sources or experiences to share on this topic? I'm very curious. My experience is the complete opposite.

At my previous job there was a Java web application and running in Kubernetes (1 vCPU and 1Gi of memory) was able to deal with at most 80 requests per second, using up almost the full 1 vCPU and ~600-700MiB of memory. That was a bit disappointing, since we were supposed to support at most ~1000rps on this API, 13+ pods is a lot, and we felt "software could do better".

A reactive guru from another team told us we should use a reactive stack, so he came in and rebuilt the app using the reactive stack. Now it was doing about 120rps on one pod (about the same memory usage), which was a good improvement, but still disappointing.

One guy on the team was motivated to rewrite the API in Go as a proof of concept, and we were blown away. With the same 1 vCPU it was now able to handle 400 requests per second, while using ~100-200MiB of memory, and having approximately 20% better response times.

> builds just as fast (at least when not using some popular build tools)

I find this a little bit of a cop-out, because almost everyone is using the popular build tools. And it's quite a chore to build a full application without those popular build tools. With Go, all batteries for building are included.

  • From your description it sounds like you're comparing an old Java program running on an old JDK with a new Go program running on a new Go runtime. These days Java has virtual threads (similar to Go's goroutines) and doesn't need a "reactive stack", and its optimising compiler and GCs blow Go out of the water without breaking a sweat.

    • I mean, what is old? How far along are frameworks these days, and what are companies using?

      That team was using Java 17. Java 21 was just released and frameworks had no meaningful support for virtual threads whatsoever.

      In my experience, most companies using Java are chronically multiple versions behind (e.g. some of my friends still in the Java world are on 11).

      Perhaps you can share some sources which prove that Java's performance blows Go out of the water without breaking a sweat? I have not seen any such articles about that in the past 3 years, besides the cherry-picked cases where the JVM JIT can optimize some small algorithmic part of the program on the fly (which is not relevant in most web applications).

      I'm happy to stand corrected.

      Edit: I found this one using a quick search myself https://medium.com/@mohnisha/java-vs-golang-performance-test... I'll check it out and see if I can reproduce it myself too. Still too bad about that gargantuan memory usage, but I guess memory in the cloud is cheap.

      4 replies →

  • Well, what frameworks were used? Also what is behind the web requests, what were they doing? Because it's comparing mostly frameworks, not languages.

    As for the build tools, unfortunately the scene is not the best on Java - but javac itself is indeed fast.

    • Yeah javac is pretty great. I was doing Kotlin for some time and I was getting very annoying by how much slower and slower running tests and doing full builds became. I thought it was some issue with the JVM ecosystem. Then I started a project with pure Java and I was blown away by how fast it was. Unit tests in my IDE running as fast as I'm used to in Go. And indeed I was surprised by the speed of the compilation step of the build too. Perhaps Kotlin is doing better now, haven't touched it in a few years, but yeah, Java made some great steps there in the past decades.

> It performs better than Go > and its optimising compiler and GCs blow Go out of the water without breaking a sweat.

Well, dandy! Since the performance gap is that big, it should be trivial to get hard data backing that up. Mind linking some representative benchmarks?

Dang, I just can't wait, same resource usage for Go and Java (RAM in particular, if you would), and Java performance that "blows Go out of the water".

> and builds just as fast

Oh? But you're comparing apples to oranges.

Go builds its source into a machine code executable, all optimizations are applied at this step. This then gets directly executed by the CPU.

Java "builds" its source into bytecode. It's a trivial transformation that then needs to actually be compiled and optimized by a virtual machine at runtime before the CPU can run it.

So then, what build time does Java have when doing AOT compilation? Again, hard numbers please, thanks.

> while offering unmatched deep, low-overhead observability.

> People might think they may enjoy another language more, but the portion of people who eventually come to regret choosing Java is probably lower than that of any other language.

Very believable statements, given that you literally work on Java for Oracle :) No need to bother to make a disclaimer about that I guess. Shameless.

  • > all optimizations

    You might want to take a look at what actually happens here. The only reason Go can compile this fast is that it does barely any optimizations. And yeah, javac also does a literal transfomation to Java byte code, no difference here with Go. One will just get a second chance of actually getting optimized via a JIT compiler.

    And Java AOT is not doing the same as Go, so again, apples to oranges. It does a complete closed universe build of the program, which requires knowing what classes are ever reachable, and then running their initializers at build time, so they can be burnt into a binary in an initialized state.

    There used to be a GNU java compiler doing pretty much what Go did, it's not hard to build, it just wouldn't be compatible with "normal Java", so the use cases would be limited.

> and builds just as fast

Source? I'm not saying you're lying but I have never seen any Java project build as fast as Go