5 ms·
"Unlike Rust, Go is really easy to pick up. It's possible to jump directly into it, and you can be writing useful programs after a single afternoon of messing a
by jerf 12y ago
"Unlike Rust, Go is really easy to pick up. It's possible to jump directly into it, and you can be writing useful programs after a single afternoon of messing around or reading. On the other hand, while basic Rust is easy to pick up, it takes a while to get used to the borrow checker (and in general understand ownership/borrowing). Additionally, most libraries make full use of advanced features (like associated types) and one needs to learn these too to be able to use the libraries."
This is pretty much why I consider these two to be in less competition than first meets the eye. Rust intrinsically involves putting more effort in to the code. You put more effort in and you get much more out, but there's a lot of code for which that's not the right tradeoff, just as there's a lot of code for which it is.
"In Go there's no obvious way to get this. The closest thing is the type called interface {} which is similar to Box<Any> in Rust or Object in Java.... Of course, I could implement a custom interface MyMessage on the various types, but this will behave exactly like interface{} (implemented on all types) unless I add a dummy method to it, which seems hackish."
I think most Go programmers stick to interface{}, but personally I put the tag method on the type, being from the Haskell side of the house on that front. In practice it turns out that often the "tag" interface grows a useful method of some sort, at which point it ceases to feel silly. If nothing else, you've got the ".Handle()" option. See also http://www.jerf.org/iri/post/2917 http://www.jerf.org/iri/post/2917 .
Also, just generally on the performance front... developers who care about performance are at this point subconsciously pretty used to being able to choose between "language like Rust or C++ that really, really cares about performance, but is hard to use" and "dynamicly-typed language that's really flexible and powerful but 50-100 times slower than the other choice". In the limit, Rust will absolutely be faster than Go, no question, but the performance penalty may be more like a factor of 2 in the end... Go's pretty fast, and while you can't go absolutely crazy with optimization C-style, you do get to play with locality optimizations with real structs and real arrays and such. Worrying about the performance differences between C and Python before you write a line of code may be perfectly valid, because the gulf is pretty large... worrying about Go vs. Rust is going to be a much narrower band of validity before you're just prematurely optimizing. Rather a lot of high performance code still has "vtables" in it, used quite extensively.
In practice, I don't expect many people to decide between Go and Rust based on performance needs on similar code... non-zero, yes, but not many. What expect people to choose between them are general software engineering complexity considerations. When it comes down to it, the reason to write Servo in Rust and why Rust needed to be created to do it isn't that there weren't languages that were "fast enough"... it's that the browser has bat-shit insane sharing patterns, complexity beyond the mind of any mere mortal, and you end up with code that either does way too much copying or crashes when it doesn't do enough, because there's no ownership management in the language. That's the sort of reason to choose Rust over Go. If you're making something that looks like a browser, or an office suite, or a big highly-integrated business workflow suite, or something like that, I'd choose Rust over Go in a heartbeat simply because Rust is designed to shine in that environment, and Go ultimately doesn't particularly offer anything to make that scale of that sort of code any better than any other statically-typed language.
- pcwalton 12y agoSpeaking as one of the founders of Servo, the reason why it couldn't be written in Go is absolutely about performance. As far as we're concerned, the most compelling reason for Servo to exist is performance, especially in layout and rendering. Many of the wins of Servo layout have come from carefully coding to the optimizer to allow it to eliminate virtual dispatch and procedure call overhead, break apart structures, stack-allocate where possible, and (in the future) use SIMD. As a result, the performance profile of most of Servo layout tends toward flat loops as opposed to deeply nested stacks of virtual call upon virtual call—much friendlier to the branch predictor, i-cache, and intraprocedural optimizations. At the same time, we get a lot of responsiveness wins from having a threaded design where pauses in one thread—most importantly, JS and the DOM—do not impact responsiveness in the other threads, which becomes very important when CSS animations are involved, especially common ones that require reflows. Now with Go, we'd have the choice between a compiler that basically doesn't do any optimizations beyond very simple ones (6g/8g) and a compiler that lacks good GC integration (gccgo). The former would negate all of the advantages of our careful coding to the optimizer and would probably make Servo layout, in parallel mode, slower than the sequential layout of other browsers. (Despite what djb says, compiler optimizations really matter!) And the latter would cause the stop-the-world GC times to spike, jeopardizing our smooth animations, which arguably matters even more than raw reflow performance to the user experience. (That's not even counting the fact that since Go's malloc is reportedly extremely slow compared to that of Java, it relies heavily on escape analysis, which gccgo doesn't do…) There are other reasons too, such as the fact that integrating a good JS garbage collector and Go's garbage collector would basically be impossible without rewriting one of them and making major sacrifices along the way (like making JS GC multithreaded or making Go's GC conservative, like Blink did with Oilpan). But performance is the main reason.
- jerf 12y ago"As far as we're concerned, the most compelling reason for Servo to exist is performance, especially in layout and rendering. Many of the wins of Servo layout have come from carefully coding to the optimizer to allow it to eliminate virtual dispatch and procedure call overhead, break apart structures, stack-allocate where possible, and (in the future) use SIMD." Yes, but if that were the only concern, you wouldn't need Rust to do it. C++ already exists, and it can do all those things. (Well, the "break apart structures" may be a bit unclean depending on exactly what you mean, but that alone wouldn't be worth writing a new language for.) My interpretation of C++'s raison d'etre in modern times is "zero-cost for abstractions you don't use", whatever its heritage may have been in the past. If that were the whole story, you just would have started a new C++ renderer from scratch. You need Rust because actually writing that code in C++ would be unmanageably complicated due to the ownership problems that Rust addresses. C++ is already unmanageably complicated (IMHO) when trying to write a browser engine, also requiring that level of performance would basically take it into the realm of the impossible. You need the complexity management first. Managing the complexity buys you the cognitive budget to write the fast code, too. It is not as if the C++ render authors do not want to write fast code, or as if they are unaware of the recipe you just laid out. I said I wouldn't write it in Go because it is already disqualified due to the complexity issues. Even if I didn't care about the performance gap, I still would have no desire to write a browser engine in it because it would be a nightmare, just like the C++ engines are, and for pretty much the same reasons, in addition to others. The performance gap between Rust and Go here is essentially unmeasurable, because in this task, Go won't even cross the finish line. (By my standards, at least. I consider the C++ renderers to also not cross the finish line. The fact that memory-unsafe code can be bashed into submission with sufficient man-millenia doesn't mean I have to agree that memory-unsafe programming languages are a good idea.)