News for hackers. Stuff that matters.
Re:Generics can make your Go code slower by stingraycharles on Wednesday March 30, 2022 @01:50PM (#30858498)
By that definition, Java is a systems language as well.

I think Go makes a better trade-off than Java, but I struggle to come up with decent examples of projects one could write in Go and not in Java. Most of the “systems” problems that Java is unsuitable for, also apply to Go.

Re:Generics can make your Go code slower by phplovesong on Wednesday March 30, 2022 @02:20PM (#30858847)
Go compiles to static binaries. Java needs the JVM. That already is a HUGE difference in "picking the right tool".

Also, the JVM is way more heavy and resource intensive than a typical Go program. Go is great for cli tools, servers, and the usual "microservices" stuff, whatever it means to you.

Re:Generics can make your Go code slower by pjmlp on Wednesday March 30, 2022 @02:32PM (#30859013)
Java can just be AOT compiled as Go, the only difference is that until recently it wasn't a free beer option to do so.
Re:Generics can make your Go code slower by cb321 on Wednesday March 30, 2022 @02:51PM (#30859294)
>until recently

Actually, for a long time (almost 20 years, I think), the gcc subsystem gcj let you do AOT compilation of Java to ELF binaries. [1] I think they had to be dynamically linked, but only to a few shared objects (unless you pulled in a lot via native dependencies, but that's kind of "on you").

I don't recall any restrictions on how to use generated code, anymore than gcc-generated object code. So, I don't think the FSF/copyleft on the compiler itself nullifies a free beer classification. :-) gcj may not have done a great job of tracking Java language changes. So, there might be a "doesn't count as 'real Java'" semantic issue.

[1] https://manpages.ubuntu.com/manpages/trusty/man1/gcj.1.html

Re:Generics can make your Go code slower by ptsneves on Wednesday March 30, 2022 @03:44PM (#30859929)
The interesting thing I always heard in the Java world is that AOT was actually a drawback as the virtual machine allowed for just in time optimizations according to hotspots. Actually if I remember correctly the word hotspot itself was even used as a tech trademark.

I was always a bit skeptical but given i was never much into Java i just assumed my skepticism was out of ignorance. Now with what I know about profile guided compilation I can see it happening; A JIT language should have a performance advantage, especially if the optimal code paths change dynamically according to workload. Not even profile guided compilation can easily handle that, unless I am ignorant of more than i thought.

Re:Generics can make your Go code slower by fluoridation on Wednesday March 30, 2022 @04:23PM (#30860324)
I've heard the exact opposite. The supposed performance benefits of JIT compared to AOT (profile-guided optimization, run-time uarch-targeted optimization) never really materialized. There's been a lot of research since the late '90s into program transformation and it turned out that actually the most effective optimizations are architecture-independent and too expensive to be performed over and over again at startup or when the program is running. At the same time, deciding when it's worthwhile to reoptimize based on new profiling data turned out to be a much more difficult problem than expected.

So the end result is that while both AOT (GCC, LLVM) and JIT (JVM, CLR) toolchains have been making gradual progress in performance, the JIT toolchains never caught up with the AOT ones as was expected in the '90s.

Re:Generics can make your Go code slower by pjmlp on Wednesday March 30, 2022 @04:48PM (#30860584)
Good luck with inlining and devirtualization across DLLs with AOT.

JIT caches with PGO get most of AOT benefits, that is why after the short stint with AOT on Android, Google decided to invest in JIT caches instead.

The best toolchains can do both, so it is never a matter of either AOT or JIT.

GCC and clang aren't investing in JIT features just for fun.

Re:Generics can make your Go code slower by fluoridation on Wednesday March 30, 2022 @05:13PM (#30860839)
What's with the snappy tone?

>Good luck with inlining and devirtualization across DLLs with AOT.

An AOT compiler/linker is unable to inline calls across DLL boundaries because DLLs present a black-box interface. A JIT compiler would run into the exact same problem when presented with a DLL whose interface it doesn't understand or is incompatible with. If you really want a call inlined the solution is to link the caller and function statically (whether the native code generation happens at compile- or run-time), not to depend on unknown capabilities of the run-time.

>The best toolchains can do both, so it is never a matter of either AOT or JIT.

You're refuting a false dichotomy no one raised.

Re:Generics can make your Go code slower by pjmlp on Thursday March 31, 2022 @01:33AM (#30864128)
I am sarcastic by nature, that is why.

JIT compilers for Java and .NET do inline across shared libraries and devirtualization, including native calls.

When people discuss A vs B there is always a dichotomy.

Re:Generics can make your Go code slower by cb321 on Wednesday March 30, 2022 @04:34PM (#30860451)
Theory and practice can diverge and it's easy to over-conclude based on either with such complex systems. For example, I have seen gcc PGO make the very same training case used to measure the profile run more slowly. One might think that impossible naively, but maybe it sounds more plausible if I put it differently - "steering the many code generation heuristics with the profile failed in practice in that case". As with almost everything in computer systems, "it all depends...."
Re:Generics can make your Go code slower by pjmlp on Wednesday March 30, 2022 @04:21PM (#30860302)
Sun was ideologically against AOT, as all commercial vendors always had some form of either AOT or JIT caches.

In fact, the JIT caches in OpenJDK come from Oracle/Bea's J/Rockit, while IBM's OpenJ9 AOT compilation is from WebSphere Real Time JVM implementation.

Re:Generics can make your Go code slower by pjmlp on Wednesday March 30, 2022 @04:14PM (#30860225)
I seldom mention it, because gcj was abandoned in 2009 when most contributors moved into the newly released OpenJDK, eventually removed from GCC tree, and it never was as foolproof as the commercial versions.
Re:Generics can make your Go code slower by koffiezet on Thursday March 31, 2022 @12:16PM (#30868895)
The problem is that a lot of software in the Java world explicitly relies on it not being compiled AOT. Any standard tomcat or jboss/wildfly application for example.
Re:Generics can make your Go code slower by jpgvm on Wednesday March 30, 2022 @02:05PM (#30858674)
Go is strictly less useful than Java because it has strictly less power. This is true for general purpose programming (though somewhat remediated through introduction of generics) it's doubly true for "systems" applications:

No access to raw threads. No ability to allocate/utilize off-heap memory (without CGo and nonsense atleast). Low throughput compared to Java JIT (unsuitable for CPU intensive tasks).

The only thing I can think of in it's favor is lower memory usage by default but this is mostly just a JVM misconception, you can totally tune it for low memory usage (in constrained env) or high memory efficiency - especially if using off-heap structures.

On a stdlib level Java mostly wins but Go has some highlights, it has an absolutely rock solid and well built HTTP and TLS/X.509/ASN1 stack for instance, also more batteries vs Java.

Overall I think if the requirement is "goes fast" I will always choose Java.

I may pick Go if the brief calls for something like a lightweight network proxy that should be I/O bound rather than CPU bound and everything I need is in stdlib and I don't need any fancy collections etc.

Re:Generics can make your Go code slower by throwaway894345 on Wednesday March 30, 2022 @02:40PM (#30859133)
I think you're mistaken on nearly every count. :)

First of all, Go and Java exist at roughly the same performance tier. It will be less work to make Java beat Go for some applications and vice versa for other applications. Moreover, typical Go programs use quite a lot less memory than typical Java programs (i.e., there's more than one kind of performance).

Secondly, Go can make syscalls directly, so it absolutely can use raw-threads and off-heap memory. These are virtually never useful for the "systems" domain (as defined above).

Thirdly, I think Go's stdlib is better if only because it isn't riddled with inheritance. It also has a standard testing library that works with the standard tooling.

Lastly, I think you're ignoring other pertinent factors like maintainability (does a new dev have to learn a new framework, style, conventions, etc to start contributing?), learning curve (how long does it take to onboard someone who is unfamiliar with the language? Are there plugins for their text editor or are they going to have to learn an IDE?), tooling (do you need a DSL just to define the dependencies? do you need a DSL just to spit out a static binary? do you need a CI pipeline to publish source code or documentation packages?), runtime (do you need a GC tuning wizard to calibrate your runtime? does it "just work" in all environments?), etc.

Re:Generics can make your Go code slower by jpgvm on Wednesday March 30, 2022 @03:09PM (#30859536)
I disagree.

Go is definitely not as fast as Java for throughput. It's gotten pretty good for latency sensitive workloads but it's simply left in the dust for straight throughput, especially if you are hammering the GC.

Sure it can make syscalls directly but if you are going to talk about a maintainability nightmare I can't think of anything worse than trying to manipulate threads directly in Go. I had to do this in a previous Go project where thread pinning was important and even that sucked.

That is just taste. Objectively collections and many other aspects of the Java stdlib completely destroy Go, I pointed out the good bits already.

Again, taste. Java has a slightly steeper and longer learning curve but that is a cost you pay once and is amortized over all the code that engineer will contribute over their tenure.

Using an IDE (especially if everyone is using the same one) is actually a productivity improvement, not an impairment but again - taste. Some people just don't like IDEs or don't like that you need to use a specific one to get the most out of a specific tech stack.

Build systems in Java by and large fall into only 3 camps, Maven, Gradle and a very small (but loud/dedicated) Bazel camp. Contrast that to Go which is almost always a huge pile of horrible Makefiles, CMake, Bazel or some other crazy homebrewed bash build system.

You don't escape CI because you used Go, if you think you did then you are probably doing Go wrong.

Java runtime trades simplicity for ability to be tuned, again taste. I personally prefer it.

So no, I don't think I am mistaken. I think you just prefer Go over Java for subjective reasons. Which is completely OK but doesn't invalidate anything I said.

Re:Generics can make your Go code slower by Thaxll on Wednesday March 30, 2022 @06:07PM (#30861416)
> Build systems in Java by and large fall into only 3 camps, Maven, Gradle and a very small (but loud/dedicated) Bazel camp. Contrast that to Go which is almost always a huge pile of horrible Makefiles, CMake, Bazel or some other crazy homebrewed bash build system.

Well Go does not need a book of 400+ pages to understand Maven.

Re:Generics can make your Go code slower by pjmlp on Thursday March 31, 2022 @04:12AM (#30864947)
It needs one to understand Go modules and how they change across language versions.
Re:Generics can make your Go code slower by Thaxll on Thursday March 31, 2022 @07:54AM (#30866184)
Go module are easy to use, compiling is even more simpler: go build .
Re:Generics can make your Go code slower by pjmlp on Thursday March 31, 2022 @08:57AM (#30866652)
If you say so,

"HERO: On the Chaos When PATH Meets Modules"

https://cs.nju.edu.cn/changxu/1_publications/21/ICSE21_02.pd...

Re:Generics can make your Go code slower by tekknik on Thursday March 31, 2022 @10:56AM (#30867911)
I’ve been writing go since it basically came out. Every single one of you’re comments is anecdotal so here we go. I’ve never, ever, encountered an issue compiling / building go code using modules. You also said in your first argument that you get no access to raw threads then a comment later said you do. It seems like you’re just advocating for people to use java because it’s what you’re comfortable with.
Re:Generics can make your Go code slower by pjmlp on Friday April 01, 2022 @04:17AM (#30876193)
I am confortable with plenty of stuff, which makes me not the target audience for Go.

"The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt."

The threads comment wasn't from me.

Re:Generics can make your Go code slower by throwaway894345 on Thursday March 31, 2022 @05:56PM (#30872638)
Pretty sure it was a different commenter who claimed no access to raw threads, but yes, the parent user can be a bit abrasive on the subject of programming languages.
Re:Generics can make your Go code slower by philosopher1234 on Wednesday March 30, 2022 @03:44PM (#30859935)
I think your use of “subjective” is avoiding discussing things that are harder to prove but matter a great deal.
Re:Generics can make your Go code slower by throwaway894345 on Wednesday March 30, 2022 @03:41PM (#30859899)
> Go is definitely not as fast as Java for throughput. It's gotten pretty good for latency sensitive workloads but it's simply left in the dust for straight throughput, especially if you are hammering the GC.

Java is better for GC throughput, but your claim was about compute throughput in general. Moreover, Go doesn't lean nearly as hard on GC as Java does in the first place (idiomatic value types, less boxing, etc), so GC throughput doesn't imply overall throughput.

> Sure it can make syscalls directly but if you are going to talk about a maintainability nightmare I can't think of anything worse than trying to manipulate threads directly in Go. I had to do this in a previous Go project where thread pinning was important and even that sucked.

Thread pinning is a very rare requirement, typically you only need it when you're calling some poorly-written C library. If this is your requirement, then Go's solution will be less maintainable, but for everyone else the absence of the foot-gun is the more maintainable solution (i.e., as opposed to an ecosystem of intermingled OS threads and goroutines).

> That is just taste. Objectively collections and many other aspects of the Java stdlib completely destroy Go, I pointed out the good bits already.

Agreed that it's taste. Agreed that Java has more collections than Go, but I think it's a good thing that Go pushes people toward slices and hashmaps because those are the right tool for the job 90% of the time. I think there's some broader point here about how Java doesn't do a good job of encouraging people away from misfeatures (e.g., inheritance, raw threads, off-heap memory, etc).

> Again, taste. Java has a slightly steeper and longer learning curve but that is a cost you pay once and is amortized over all the code that engineer will contribute over their tenure.

Java has a significantly steeper/longer curve--it's not only the language that you must learn, but also the stdlib, runtime, tools, etc and these are typically considerably more complicated than Go. Moreover, it's a cost an engineer pays once, but it's a cost an organization pays over and over (either because they have to train people in Java or narrow their hiring pool).

> Build systems in Java by and large fall into only 3 camps, Maven, Gradle and a very small (but loud/dedicated) Bazel camp. Contrast that to Go which is almost always a huge pile of horrible Makefiles, CMake, Bazel or some other crazy homebrewed bash build system.

Go has one build system, `go build`. Some people will wrap those in Makefiles (typically very lightweight makefiles e.g., they just call `go build` with a few flags). A minuscule number of projects use Bazel--for all intents and purposes, Bazel is not part of the Go ecosystem. I haven't seen any "crazy homebrewed bash build system" either, I suspect this falls into the "for all intents and purposes not part of the Go ecosystem" category as well. I've been writing Go regularly since 2012.

> You don't escape CI because you used Go, if you think you did then you are probably doing Go wrong.

I claimed the CI burden is lighter for Go than Java, not that it goes away entirely.

> Java runtime trades simplicity for ability to be tuned, again taste. I personally prefer it.

I think it's difficult to accurately quantify, but I don't think it's a matter of taste. Specifically, I would wager that Go's defaults + knobs are less work than Java for something like 99% of applications.

> So no, I don't think I am mistaken. I think you just prefer Go over Java for subjective reasons. Which is completely OK but doesn't invalidate anything I said.

I agree that some questions are subjective, but I think on many objective questions you are mistaken (e.g., performance, build tool ecosystem, etc).

Re:Generics can make your Go code slower by jen20 on Wednesday March 30, 2022 @03:16PM (#30859629)
> On a stdlib level Java mostly wins

This isn't even true compared to other comparable platforms like .NET, let alone Go which has hands down the most useful and well constructed standard library in existence (yes, even better than Python).

Re:Generics can make your Go code slower by jpgvm on Wednesday March 30, 2022 @03:31PM (#30859782)
Yeah I don't buy that.

Especially not when things like this exist: https://pkg.go.dev/container

And things like this don't: https://docs.oracle.com/en/java/javase/17/docs/api/java.base...

As I mentioned Go does have a great HTTP and TLS stack but that doesn't do enough to put it on the same level.

Re:Generics can make your Go code slower by earthboundkid on Wednesday March 30, 2022 @08:40PM (#30862574)
Go didn’t have any container types in the standard library because it didn’t have generics and slice plus hash map solve 90% of what you need. I think an avalanche of container libraries are coming to Go. I already wrote my own deque and have seen a few others.
Re:Generics can make your Go code slower by philosopher1234 on Wednesday March 30, 2022 @02:30PM (#30858987)
This is an argument from edge case capabilities that completely ignores maintenance costs + development time. Seems very naive to me.
Re:Generics can make your Go code slower by BobbyJo on Wednesday March 30, 2022 @02:44PM (#30859190)
Totally agree. If the argument is strictly more power is always better, then C++ would always win. Why doesn't it? Exactly what you reference, dev time and maintenance.

Go was designed for simplicity. Of course it's not the fastest or most feature rich. It's strong suit is that I can pop open any Go codebase and understand what's going on fairly quickly. I went from not knowing any Go to working with it effectively in a large codebase in a couple weeks. Not the case with Java. Not the case with most languages.

Re:Generics can make your Go code slower by jpgvm on Wednesday March 30, 2022 @03:14PM (#30859602)
That wasn't the argument though, you are attacking a strawman. The argument was much more nuanced if you bothered to read it.

Essentially it boils down to this. If I am writing -systems- software and I'm going to choose between Go or Java then the list of things I pointed out are the main differentiating features along with raw throughput which matters for things like databases which need to be able to do very fast index/bitmap/etc operations.

Go is great for being simple and easy to get going. However that is completely worthless in systems software that requires years of background knowledge to meaningfully contribute to. The startup cost of learning a new codebase (or entirely new programming language) pales in comparison to the requisite background knowledge.

Re:Generics can make your Go code slower by BobbyJo on Wednesday March 30, 2022 @04:07PM (#30860158)
> Go is strictly less useful than Java because it has strictly less power.

Literally sentence one, so calling my argument straw-man is dishonest.

> Essentially it boils down to this. If I am writing -systems- software and I'm going to choose between Go or Java then the list of things I pointed out are the main differentiating features along with raw throughput which matters for things like databases which need to be able to do very fast index/bitmap/etc operations.

All true. In my experience though, the long tail of maintenance and bug fixes tend to result in decreasing performance over time, as well as a slowing of new feature support.

All of that being said, these are all fairly pointless metrics when we can just look at the DBs being adopted and why people are adopting them. Plenty of projects use Go because of Go's strengths, so saying "that is completely worthless in systems software" is verifiably false. It's not worthless in any software, worth less maybe, but not worthless.

Re:Generics can make your Go code slower by jpgvm on Wednesday March 30, 2022 @03:11PM (#30859563)
It's not. If you are building a database or other "systems" software these are very relevant capabilities.

Also development time of Java may be slightly longer in the early stages but I generally find refactoring of Java projects and shuffling of timelines etc is a ton easier than Go. So I think Java wins out over a longer period of time even if it starts off a bit slower.

It's far from naive. I have written a shitton of Go code (also a shitton of Java if that wasn't already apparent).

Re:Generics can make your Go code slower by philosopher1234 on Wednesday March 30, 2022 @03:20PM (#30859672)
You may not personally be naive, but i was talking about your analysis, not you.

>Also development time of Java may be slightly longer in the early stages but I generally find refactoring of Java projects and shuffling of timelines etc is a ton easier than Go. So I think Java wins out over a longer period of time even if it starts off a bit slower.

I think this topic is far too large to be answered in this brief sentence. I also think it deserves a higher allocation of your words than what you spared for java's capabilities :)

But yes, I see now that you are interested purely in performance in your argument and definition of systems software, in which case what you're saying may be true.

Re:Generics can make your Go code slower by geodel on Wednesday March 30, 2022 @02:10PM (#30858735)
Go has user defined value types which Java does not yet. It makes huge difference in memory density for typical data structures. This makes Go more suitable to low overhead web services, cli tools running on few MBs which Java at least needs few hundred MBs
Re:Generics can make your Go code slower by pionar on Wednesday March 30, 2022 @02:14PM (#30858789)
> Go has user defined value types which Java does not yet.

C# has this. A lot of people overlook C# in this area, probably because until recently, it was not cross-platform.

Re:Generics can make your Go code slower by shlurpy on Wednesday March 30, 2022 @09:30PM (#30862887)
The games world has understood C# to be a reasonably capable language for a while. But that world often feels disjoint with the enterprise software world where Go has thrived, eating into Java's niche.
Re:Generics can make your Go code slower by pjmlp on Thursday March 31, 2022 @04:10AM (#30864942)
On my enterprise world, it is all about .NET and Java.

Unless one is doing DevOps related tasks involving some form of Docker or Kubernetes, it isn't even something people bother with.

And even then, most automatition tasks are written in a mix of Python and PowerShell code.

Re:Generics can make your Go code slower by tekknik on Thursday March 31, 2022 @10:50AM (#30867832)
> The games world has understood C# to be a reasonably capable language for a while.

Only in unity, the other major engine in the room still uses C++ for performance reasons.

Re:Generics can make your Go code slower by coder543 on Wednesday March 30, 2022 @02:31PM (#30859010)
> By that definition, Java is a systems language as well.

I would fully agree that Java is a systems language.

However, the definition of "systems language" has been a contentious issue for a very long time, and that debate seems unlikely to be resolved in this thread. I don't think the term itself is very useful, so it's probably better if everyone focuses on discussing things that actually matter to the applications they're trying to develop instead of arguing about nebulous classifications.

Re:Generics can make your Go code slower by tptacek on Wednesday March 30, 2022 @04:34PM (#30860449)
People do huge amounts of systems programming in Java, including in systems that are incredibly performance-sensitive.
Re:Generics can make your Go code slower by throwaway894345 on Wednesday March 30, 2022 @02:07PM (#30858704)
I don't think it's useful to frame "fitness for a given domain" as a binary, but yes, Java is often used successfully for this domain (although personally I think Go is an even better fit for a variety of reasons).