Erik Engheim
2 min readApr 30, 2021

--

What exactly are you trying to prove with this narrowly defined micro-benchmark?

Doing performance tests isn't really something I do so I cannot really comment on the validity of these tests. Somebody who is more familiar with performance testing Go would have to do it.

Simple benchmarks like this will often favor languages like Java and C# because they can exploit the fact that they have very cheap allocation using bump pointers. Java and C# have much faster allocation than Go, but the price they pay for this is much slower freeing of memory and much longer pauses to perform GC analsysis.

In a real system however in use over longer time periods, C# code will have to pay the price of doing a lot of copying in memory to do compaction. Go doesn't have to do this. In fact it gives real-time performance for garbage collection.

But if you run a micro-benchmark, then Go will pay extra for:

1. A more complex allocator which make sure it doesn't fragment memory. This however avoid the need to do compaction later, which C# has to pay the price for in a real system.

2. All memory is initialized to zero when allocated in Go.

My point about Go as a system language isn't that it has the highest performance out of the box but that it has a high level of transparency about how it works. That is important when you try to optimize a system.

E.g. Java would in microbenchmarks always beat Objective-C, but Objective-C had way more opportunities for optimizing code for anyone who wanted to do it. In practice, Objective-C apps on iOS always ran with much better performance than Java apps on Android.

JIT compiled languages is often harder to reason about. I am not sure what sort of JIT C# uses though, whether it is a tracing JIT or method JIT. E.g. Julia which I am most familiar with uses a method JIT which is deterministic so I can easily lookup what code gets generated for a given method ahead of time. However for something like JS that would be impossible.

--

--

Erik Engheim
Erik Engheim

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Responses (1)