4 ms·
Speaking 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 comp
by pcwalton 12y ago
Speaking 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.)
- pcwalton 12y agoOh, I definitely agree that safety is the main reason for choosing Rust over C++ in particular. The slightly better alias analysis and dereferenceability-of-pointer guarantees that Rust can provide over C++ are cool, but I don't think it'll make or break our layout engine.
- slimsag 12y agoI'd like to see Rust put more focus into making SIMD work nicely. I think Rust is a great alternative for C++ needed projects -- but it completely lacks SIMD in at least the upcoming 1.0 release. More importantly, there isn't any language that focuses on _making SIMD work right_ -- even C/C++ do an awful job of this with it's tacked-on __mm_foobar functions. Rusts idea of having SIMD live as near-primitive datatypes (f32x4 etc) follows Dart a bit and overall I think it's a good approach -- albeit very incomplete right now. I seriously hope that emphasis will be placed into making SIMD feel like a first-class citizen in the language and not a tacked-on feature as I've seen in so many other languages.
- pcwalton 12y agoI agree that we need to work on SIMD post-1.0. I really want to make use of it in Servo :)
- sanxiyn 12y agoI am the author of current SIMD support in Rust, and my tentative plan is to implement something like Sierra, a SIMD extension for C++. http://sierra-lang.org/ http://sierra-lang.org/