by dahfizz · 4y ago · 0 comments
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.
I'm saying the performance of Go can sometimes be surprisingly fast. Not that it's magic.
Don't write Rust as if it was Go. That doesn't say anything meaningful about either Go or Rust.
> 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.
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++.
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.
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.
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.
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.
> 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...