Why is Go so slow (compared to Java)?

go vs java performance 2019
go vs java memory usage
should i learn go or java
from go to java
golang vs java
go garbage collection vs java
go vs java future
is go faster than c++

As we could see from The Computer Language Benchmarks Game in 2010:

  • Go is on average 10x slower than C
  • Go is 3x slower than Java !?

How can this be, bearing in mind that Go compiler produces native code for execution? Immature compilers for Go? Or there is some intrinsic problem with the Go language?

EDIT: Most answers deny intrinsic slowness of Go languge, claiming the problem resides in immature compilers. Therefore I've made some own tests to calculate Fibonacci numbers: Iterative algorithm runs in Go (freebsd,6g) with the same speed as in C (with O3 option). The dull recursive one runs in Go 2 times slower than in C (with -O3 option; with -O0 - the same). But I haven't seen 10x fall as in the Benchmarks Game.

The 6g and 8g compilers are not particularly optimising, so the code they produce isn't particularly fast.

They're designed to run fast themselves and produce code that's OK (there is a bit of optimisation). gccgo uses GCC's existing optimisation passes, and might provide a more pointful comparison with C, but gccgo isn't feature-complete yet.

Benchmark figures are almost entirely about quality of implementation. They don't have a huge amount to do with the language as such, except to the extent that the implementation spends runtime supporting language features that the benchmark doesn't really need. In most compiled languages a sufficiently clever compiler could in theory strip out what isn't needed, but there comes a point where you're rigging the demo, since very few real users of the language would write programs that didn't use that feature. Moving things out of the way without removing them entirely (e.g. predicting virtual call destinations in JIT-compiled Java) starts to get tricky.

FWIW, my own very trivial test with Go when I was taking a look at it (a loop of integer addition, basically), gccgo produced code towards the fast end of the range between gcc -O0 and gcc -O2 for equivalent C. Go isn't inherently slow, but the compilers don't do everything, yet. Hardly surprising for a language that's 10 minutes old.

When can Golang be as fast as Java?, When I see how often Golang is compared to Java, it makes me cringe. These are Loads of people use Python or Ruby, even though their runtimes/​interpreters are known to be very slow. Unless you have Why should I use Go (​Golang)?. Go: 3.73 826,488 611 4.10 88% 6% 2% 14% Java: 3.27 714,144 2183 7.54 47% 60% 66% 58% k-nucleotide; source secs mem gz busy cpu load Go: 12.67 150,584 1722 47.44 95% 90% 93% 96% Java: 9.14

In the next release of the Go FAQ, something similar to the following should appear.


Why does Go perform badly on benchmark X?

One of Go's design goals is to approach the performance of C for comparable programs, yet on some benchmarks it does quite poorly, including several in test/bench. The slowest depend on libraries for which versions of comparable performance are not available in Go. For instance, pidigits depends on a multi-precision math package, and the C versions, unlike Go's, use GMP (which is written in optimized assembler). Benchmarks that depend on regular expressions (regex-dna, for instance) are essentially comparing Go's stopgap regexp package to mature, highly optimized regular expression libraries like PCRE.

Benchmark games are won by extensive tuning and the Go versions of most of the benchmarks need attention. If you measure comparable C and Go programs (reverse-complement is one example), you'll see the two languages are much closer in raw performance than this suite would indicate.

Still, there is room for improvement. The compilers are good but could be better, many libraries need major performance work, and the garbage collector isn't fast enough yet (even if it were, taking care not to generate unnecessary garbage can have a huge effect).

And here's some more details on The Computer Benchmarks Game from a recent mailing list thread.

Garbage collection and performance in gccgo (1)

Garbage collection and performance in gccgo (2)

It's important to note that the Computer Benchmarks Game is just a game. People with experience in performance measurement and capacity planning carefully match like with like over realistic and actual workloads; they don't play games.

Why do people still say Java is slow?, The Java code was orders of magnitude slower than the C++ code. Of course this is comparing apples with oranges. But the point is that the Java implementation  WordPress is a great option for smaller sites where performance isn't so critical, but when it comes to high-performance, multi-million-user, enterprise applications, it's not so widely used. Node, Go, Java, and C# are far more suitable in these situations, as the benchmarks above clearly show.

My answer isn't quite as technical as everyone else's, but I think it's still relevant. I saw the same benchmarks on the Computer Benchmarks Game when I decided to start learning Go. But I honestly think all these synthetic benchmarks are pointless in terms of deciding whether Go is fast enough for you.

I had written a message server in Python using Tornado+TornadIO+ZMQ recently, and for my first Go project I decided to rewrite the server in Go. So far, having gotten the server to the same functionality as the Python version, my tests are showing me about 4.7x speed increase in the Go program. Mind you, I have only been coding in Go for maybe a week, and I have been coding in Python for over 5 years.

Go is only going to get faster as they continue to work on it, and I think really it comes down to how it performs in a real world application and not tiny little computational benchmarks. For me, Go apparently resulted in a more efficient program than what I could produce in Python. That is my take on the answer to this question.

Is Java slow? Compared to C++, it's faster than you think, Is Java slow? The fact remains that Java is an interpreted language. In contrast​, C++ -- a language which Java is often compared to -- is statically replacing it with a trap that can catch an attempt to go down that path, if one  Of the available (non-beta) Java releases out today, the Oracle JDK looks to be the most performant and so is recommended for use with Eclipse. Eclipse Being out of Date. There are a number of reasons why being on a recent version of Eclipse is important.

Things have changed.

I think the current correct answer to your question is to contest the notion that go is slow. At the time of your inquiry your judgement was justified, but go has since gained a lot of ground in terms of performance. Now, it's still not as fast as C, but is no where near being 10x slower, in a general sense.

Computer language benchmarks game

At the time of this writing:

source  secs    KB      gz      cpu     cpu load

Go      0.49    88,320  1278    0.84    30% 28% 98% 34%
C gcc   0.42    145,900 812     0.57    0% 26% 20% 100%

Go      2.10    8,084   603 2.10    0% 100% 1% 1%
C gcc   1.73    1,992   448 1.73    1% 100% 1% 0%

Go      1.97    3,456   1344    5.76    76% 71% 74% 73%
C gcc   1.36    2,800   1993    5.26    96% 97% 100% 97%

Go      3.89    369,380 1229    8.29    43% 53% 61% 82%
C gcc   2.43    339,000 2579    5.68    46% 70% 51% 72%

Go      15.59   952 900 62.08   100% 100% 100% 100%
C gcc   9.07    1,576   910 35.43   100% 99% 98% 94%

Go      3.96    2,412   548 15.73   99% 99% 100% 99%
C gcc   1.98    1,776   1139    7.87    99% 99% 100% 99%

Go      21.73   952 1310    21.73   0% 100% 1% 2%
C gcc   9.56    1,000   1490    9.56    1% 100% 1% 1%

Go      15.48   149,276 1582    54.68   88% 97% 90% 79%
C gcc   6.46    130,076 1500    17.06   51% 37% 89% 88%

Go      5.68    30,756  894 22.56   100% 100% 99% 99%
C gcc   1.78    29,792  911 7.03    100% 99% 99% 98%

Though, it does suffer brutally on the binary tree benchmark:

Go      39.88   361,208 688 152.12  96% 95% 96% 96%
C gcc   3.28    156,780 906 10.12   91% 77% 59% 83%

Java Performance: In-Depth Advice for Tuning and Programming Java , In-Depth Advice for Tuning and Programming Java 8, 11, and Beyond Scott Oaks Sierra (and it if did, it would be so very, very slow compared to Mac OS 7.5). Oh, Go Ahead, Prematurely Optimize Donald Knuth is widely credited with  If a C program is slow, it is slow in an obvious way: by executing a lot of statements. Compared with the cost of operations in C, high-level operations on objects (especially reflection) or strings can have costs that are not obvious.

Despite the not so good efficiency of Go about the CPU cycles usage, the Go concurrency model is much faster than the thread model in Java, for instance, and can be comparable to C++ thread model.

Note that in the thread-ring benchmark, Go was 16x faster than Java. In the same scenario Go CSP was almost comparable to C++, but using 4x less memory.

The great power of Go language is its concurrency model, Communicating Sequential Processes, CSP, specified by Tony Hoare in 70's, being simple to implement and fit for highly concurrent needs.

Practical Data Structures with C++, C#, and Java, We leave the implementation of this program as an exercise. In line 21, We return Example 1: Print Buffer When a user sends documents to the printer, the documents must go Printers are very slow compared with the speed of the CPU​. Despite the not so good efficiency of Go about the CPU cycles usage, the Go concurrency model is much faster than the thread model in Java, for instance, and can be comparable to C++ thread model. Note that in the thread-ring benchmark, Go was 16x faster than Java. In the same scenario Go CSP was almost comparable to C++, but using 4x less memory.

The Definitive Guide to Terracotta: Cluster the JVM for Spring, , The efforts quickly revealed that the network was painfully slow compared to the CPU and that when needed (RMI, JMS, and even JDBC can be used to share objects across Java The less we write to disk, the faster we go, remember? Internet Explorer caches web pages you visit and cookies coming from those pages. While designed to speed up browsing, if left unchecked the burgeoning folders can sometimes slow IE to a crawl or cause other unexpected behavior. In general, the less is more principal works well here — keep the Internet Explorer cache small and clear it often.

Parallel Computing: Software Technology, Algorithms, Architectures , M.P.so |- MP, Go --MP. as - Pont-so - Pinroad-Go. For N = 384, the Java implementations are only 1.6 to 2.2 times slower than the C implementations. 4. Viruses. If your comp has been bombarded with viruses in the past, then it's most likely the reason you Minecraft version is so laggy. User Info: MrLegoMan30. MrLegoMan30 - 8 years ago 1 1. Here is what i would do; change your performance to 'Max FPS', flip your open GL to 'on', change your render distance to 'short' when in jungles, normal

The Cucumber for Java Book: Behaviour-Driven Development for , If your Cucumber tests are going to add any value to your customers, this is the most We might choose to go back and fill that gap, either by writing a new test or by but they are still relatively slow compared to our scenarios and unit tests. 1) C++ grammar is more complex than C# or Java and takes more time to parse. 2) (More important) C++ compiler produces machine code and does all optimizations during compilation. C# and Java go just half way and leave these steps to JIT.

  • To be fair, C is ASM in disguise, and Java has some serious optimisations under the hood these days.
  • Perhaps the benchmark also does not reflect the strengths of Go. It may be that other benchmarks are actually faster than this. Besides, often it's not the performance but the readability of the code that counts most.
  • @extraneon: I agree. Remember, Go is designed for Google and Google routinely runs code on 2 million cores. The Benchmarks Game uses only 4 cores, I believe.
  • @extraneon: I agree in general, but Go was specifically designed with speed in mind, as in, "resulting programs run nearly as quickly as comparable C or C++ code."
  • Your question assumes too much: "Most answers deny intrinsic slowness of Go languge" is an incorrect phrase for use in a question. Do you have a question to ask, or a statement to make? Please see c2.com/cgi/wiki?HostileStudent to understand your error.
  • Moreover, it may be that Go programs in The Computer Language Benchmarks Game are not that optimized as C and Java ones are.
  • What about between gcc -O0 and gcc -O3 ? Is there even the intention that the compilers will "do everything" ?
  • @igouy: well, I'm pretty sure that there's an intention gccgo will do garbage collection, which currently it doesn't. There are still some features to go into the g compilers too, for instance they don't currently use host threads particularly well (specifically, the goroutine scheduler isn't pre-emptive). Beyond that, I don't know Google's plans, whether the g compilers will ever be fiercely optimising, or if only gccgo will.
  • @xitrium: I think the intention for Go is that implementations should not be required to schedule co-operatively, they can pre-empt if they want. See for example code.google.com/p/go/issues/detail?id=543, which hasn't been closed as "nonsensical, fixing this so-called bug would contradict the Go language definition", which it should be if Go implementations are forbidden to pre-empt :-) The issue was compounded by the fact that by default Go used only a single host thread no matter how many goroutines were runnable.
  • The answer might be a bit outdated as of now. Recently, the first beta of Go 1.1 was released, they state that performance of compiled programs increases by about 30% to 40%. Somebody please do these tests again.
  • And here some details from that same thread that you have excluded - groups.google.com/group/golang-nuts/msg/2e568d2888970308
  • It's important to note that "benchmarks are a crock" - not just the benchmarks published as the benchmarks game - shootout.alioth.debian.org/flawed-benchmarks.php
  • (and everybody...) Sure it's a "game", but when I see that Go is only two times slower than the fastest on these benchmarks, my first impression is "wow, Go seems fast", because I know these benchmarks are flawed. On the contrary, when I see Ruby being 65 times slower than the fastest, I think to myself "not gonna use Ruby for my next concurrent-numerically-intensive endeavour". So it may be a "game", but there's some truth in it if you take it with a grain of salt.
  • Capacity planning has a very important aspect: cost. Whether you will need X boxes or 2*X makes a huge difference in the end. And since no one can estimate just what is going to run in the future on those, the best bet is to take a look at different workloads. I've checked a few implementations of these and found them to be mostly OK. I think the results can be used as a base for estimations.