News for hackers. Stuff that matters.
Re:I/O is no longer the bottleneck by dahfizz on Saturday November 26, 2022 @08:04AM (#33752300)
I mean, Go is closer to C than Python is. But Go is still a garbage collected language with a runtime. It's not going to come close to the limits of performance that C offers
Re:I/O is no longer the bottleneck by morelisp on Saturday November 26, 2022 @08:14AM (#33752355)
Having played with this a previous time it was posted and looking at the profiler results, the main difference between the Go and C isn't due to any memory allocations but rather the lack of in-place update and slightly higher cost from being general-purpose in Go's hash table.
Re:I/O is no longer the bottleneck by sidlls on Saturday November 26, 2022 @01:50PM (#33755416)
I'm fairly certain that if one wrote C (or C++) programs with the same safety targets that Rust has out-of-the-box the performance is close, if not (for practical purposes) identical.

Of course, to do much useful (and performant) in Rust one often has to break out `unsafe`, which eliminates some of the out-of-the-box guarantees for safety--and in some cases makes one wonder if it's worth all the overhead instead of just using C or C++.

Re:I/O is no longer the bottleneck by morelisp on Saturday November 26, 2022 @02:52PM (#33756011)
> the same safety targets

Rust's selling point is that the safety targets' costs are dev/compile-time ones. There should not be a difference unless the C/C++ code requires some IB or extremely manual memory management trickery, which it doesn't; and Go offers basically the same memory safety guarantees as Rust in this regard and is (slightly) faster.

In this case it's really almost entirely about the speed of the hash table.

Re:I/O is no longer the bottleneck by sidlls on Saturday November 26, 2022 @05:07PM (#33757290)
I was referring to the overhead of development time. Rust is more complex than C, at least, and even after having gained proficiency coding in Rust still takes more time than writing an equivalent C program.

And "zero-cost" is misleading. There are definitely performance impacts from the implicit (and unadvertised explicit) bounds checking some of Rust's features come with. Writing a C program to an equivalent level of safety would have similar performance impacts. Hence, for as close to the same safety as possible, Rust and C should be almost identical in terms of performance.

Re:I/O is no longer the bottleneck by k__ on Saturday November 26, 2022 @09:00AM (#33752679)
That's probably the reason why Go got many people switching from their scripting languages and didn't end up as the C killer it was sold in the beginning.
Re:I/O is no longer the bottleneck by taf2 on Saturday November 26, 2022 @09:37AM (#33752988)
I never remember it being sold as a C killer maybe as a Java killer?
Re:I/O is no longer the bottleneck by habibur on Saturday November 26, 2022 @09:49AM (#33753077)
It was sold as C killer in the beginning.

And then a few years later there was an article that said, the Go engineers were surprised when they saw C/C++ coders weren't switching to Go rather Python/Ruby coders were "upgrading" to Go.

Re:I/O is no longer the bottleneck by capableweb on Saturday November 26, 2022 @10:02AM (#33753188)
golang.org circa 2010:

> go is ... fast

> Go compilers produce fast code fast. Typical builds take a fraction of a second yet the resulting programs run nearly as quickly as comparable C or C++ code.

https://web.archive.org/web/20100217123645/http://golang.org...

That seems to me like they were trying to say "If you want C/C++ performance but nicer/easier syntax, you can use Go", which turned out to be not that true in the end.

Edit: the old "Language Design FAQ" also goes further in detail on how the envision (the first version of the) language: https://web.archive.org/web/20100211104313/http://golang.org...

Re:I/O is no longer the bottleneck by dagw on Saturday November 26, 2022 @10:22AM (#33753350)
It was more sold as a C++ killer than a C killer.
Re:I/O is no longer the bottleneck by forty on Saturday November 26, 2022 @10:46AM (#33753530)
I believe Go was created to replace python at Google.
Re:I/O is no longer the bottleneck by pdimitar on Saturday November 26, 2022 @09:11AM (#33752764)
That's exactly my reason to use it: fast prototyping and ability to replace bash scripts (as they become too unwieldy to maintain and expand from one point and on).

I've also successfully made an MVP with Golang which I then proceeded to rewrite in Rust in almost only one go and almost without blockers along the way.

Golang is pretty good but it still lacks important things like algebraic data types, and they're hugely important for fearless refactoring and correctness.

Re:I/O is no longer the bottleneck by eloff on Saturday November 26, 2022 @10:44AM (#33753519)
For a script like this your be surprised. If you don't do too much allocation, the garbage collector need not run. In fact it's common to disable it at the start. Now you can allocate much faster than C because you never clean up after yourself!

A real world example is esbuild, the author implemented it both Rust and Go initially. The Go version was faster and the code simpler. Which is why it's implemented in Go.

Re:I/O is no longer the bottleneck by leethaxor on Saturday November 26, 2022 @10:57AM (#33753649)
> A real world example is esbuild, the author implemented it both Rust and Go initially. The Go version was faster and the code simpler. Which is why it's implemented in Go.

But why is swc faster than esbuild then? The code isn't even considerably more complex.

Re:I/O is no longer the bottleneck by tail_exchange on Saturday November 26, 2022 @11:38AM (#33754116)
You can find the comments from the ESBuild author here on HN:

https://news.ycombinator.com/item?id=22336284

Re:I/O is no longer the bottleneck by leethaxor on Saturday November 26, 2022 @12:19PM (#33754581)
Rust compiler is much faster today than it was in 2020, btw.

> This is a side project and it has to be fun for me to work on it.

I respect this 100% - but then we shouldn't assume Go is better than Rust just based on that esbuild used it instead of Rust.

Re:I/O is no longer the bottleneck by eloff on Saturday November 26, 2022 @11:21AM (#33753941)
Because different programs, implemented differently, run at different speeds...

I'm saying the performance of Go can sometimes be surprisingly fast. Not that it's magic.

Re:I/O is no longer the bottleneck by leethaxor on Saturday November 26, 2022 @11:28AM (#33754012)
So you're saying they wrote exactly the same program in Go and Rust for the comparison, changing the syntax only? Well then it's no surprise the Go version was faster.

Don't write Rust as if it was Go. That doesn't say anything meaningful about either Go or Rust.

Re:I/O is no longer the bottleneck by eloff on Saturday November 26, 2022 @12:02PM (#33754378)
Actually he wrote the Rust version first, so you're wrong jumping to conclusions.

I'm not trying to say Go is faster than Rust, it's usually slower. But there are always exceptions to the rule. The Go code, on the other hand, is usually simpler and quicker to write. For that reason I'd prefer Go if the problem lends itself to a garbage collected language.

Re:I/O is no longer the bottleneck by leethaxor on Saturday November 26, 2022 @12:17PM (#33754566)
So what did you mean by this?

> Because different programs, implemented differently, run at different speeds...

We're talking about two programs with exactly the same purpose - ingest TypeScript and output JavaScript. It's a pretty clear-cut comparison, IMHO.

> The Go code, on the other hand, is usually simpler and quicker to write

I'm writing Go code at work, and Rust code mostly for fun (but used it at work too). I'd say this has changed significantly in the last 2 years. Now with rust-analyzer and much improved compiler output, writing Rust is very simple and quick too. I guess getting into Rust can be a little harder if you've only ever used GCed languages before, but it's not that hard to learn - and once you do it's super-effective. And the type inference of Rust is a huge reason why I'm using it - while Go has none.

Another thing to consider - usually the code in Go is much more about writing algorithms yourself instead of using library functionality (this is changing slowly thanks to the new support of generics but most code hasn't caught up yet and there aren't good libs using it so far). The resulting code in Go can be convoluted a lot and contain very hidden bugs. My Go code is usually 2-3x longer than the equivalent in TypeScript or Rust.

Re:I/O is no longer the bottleneck by eloff on Saturday November 26, 2022 @01:21PM (#33755165)
> We're talking about two programs with exactly the same purpose - ingest TypeScript and output JavaScript. It's a pretty clear-cut comparison, IMHO.

There are an infinite number of ways to design two programs for that task, with different trade-offs. You can't draw conclusions about which language is faster based on two different implementations by different people.

> Go is great, I like it. Rust is great too. I recommend you to do what the esbuild author did - test it and choose for yourself, don't bother too much about others' opinion.

I'm actually writing Rust code the last two years. It's been a while since I've used Go. But I'd rather use Go if the problem allows for a garbage collector. It's just simpler than managing it manually in Rust with the borrow checker and its rules. This is my opinion, nobody else's.

Re:I/O is no longer the bottleneck by stavros on Saturday November 26, 2022 @01:48PM (#33755389)
The GP didn't say that, maybe they wrote Go as if it were Rust, for all we know.
Re:I/O is no longer the bottleneck by cma on Saturday November 26, 2022 @11:12AM (#33753835)
You could LD_PRELOAD a free that doesn't do anything in C too or a macro define to really make it no cost.
Re:I/O is no longer the bottleneck by eloff on Saturday November 26, 2022 @11:20AM (#33753920)
You'd need to change malloc too so it doesn't do extra work. You could do it. Go obviously isn't going to be faster than well written C. But sometimes you can be surprised.