11 ms·
> Mozilla used Rust to build Stylo, the CSS engine in Firefox (replacing approximately 160,000 lines of C++ with 85,000 lines of Rust). I would have loved to s
by nickelcitymario 6y ago
> Mozilla used Rust to build Stylo, the CSS engine in Firefox (replacing approximately 160,000 lines of C++ with 85,000 lines of Rust).
I would have loved to see two competing teams rewrite it, one in C++ and the other in Rust.
Saying that the rewrite is better does nothing to say WHY it's better. Refactored code is almost always radically better, even when it's in the same language, for reasons that might be insulting to explain on HN.
Point is, this is not an apples-to-apples comparison.
(I'm not arguing Rust isn't better. Nor that cutting your code base nearly in half isn't impressive. Simply that this single metric on their part seems like weak sauce.)
- deleted 6y ago[deleted]
- steveklabnik 6y agoThey tried to do it in C++ twice before the Rust. So what you’re asking for sorta kinda happened.
- nickelcitymario 6y agoI didn't know that! Thanks for that context, it makes their claim far more interesting in my books.
- professor_v 6y agoThey don't explicitly state that the rewrite is better? They just mention that they reduced the amount of code from 160,000 to 85,000 lines. Using competing teams for this purpose seems like a waste of money to me.
- tehbeard 6y agoLess of a waste of money than what Mozilla spends on CEO/middle management.
- swsieber 6y agoIt could very much be from the second system effect though. A rewrite in C++ from a competing team would provide a control for that. As many others have mentioned though, the real kicker is that they did attempt a rewrite twice in C++ aiming for the features of the rust one; those didn't work out.
- waheoo 6y agoYou're making some big assumptions here and I don't think you even realise it.
- nickelcitymario 6y ago> Using competing teams for this purpose seems like a waste of money to me. You're not wrong! My point was more that we can't take this single data point as proof of Rust's superiority.
- dblohm7 6y ago> Using competing teams for this purpose seems like a waste of money to me. That's not how it was done.
- KwanEsq 6y agoMozilla already tried re-writing the CSS engine in C++ before. They failed. C++ simply wasn't usable for writing a parallel CSS engine. "This top-down structure is ripe for parallelism; however, since styling is a complex process, it’s hard to get right. Mozilla made two previous attempts to parallelize its style system in C++, and both of them failed. But Rust’s fearless concurrency has made parallelism practical!" https://blog.rust-lang.org/2017/11/14/Fearless-Concurrency-In-Firefox-Quantum.html#stylo-a-parallel-css-engine https://blog.rust-lang.org/2017/11/14/Fearless-Concurrency-I...
- Garbage 6y agoThis blog from Mozilla [1] explains why rendering CSS is such a complex process. [1] https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/ https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-en...
- johnnycerberus 6y agoSo you are telling me that a parallel CSS engine can't be usable if written in C++ but large scale particle/molecule simulators, AAA game engines and other high-fidelity simulator environments are 100% C++ codebases?
- miked85 6y ago> Refactored code is almost always radically better Sometimes it is, but it is hardly the rule. New issues will always be introduced. Also, some developers get into an endless cycle of unnecessary refactoring just to use the latest and greatest of some library or framework for no real technical reason.
- nickelcitymario 6y agoI'm not saying refactoring is always worthwhile (it usually isn't, in my experience anyway). But the refactor is generally done with the benefit of hindsight of all the things you would have done differently if only you'd known then what you know now. It's like saying that the second draft or edited manuscript of a novel isn't going to be better than the initial draft. Of course it's better the second time. In theory, you fixed what was wrong with the first one and implemented new and/or improved ideas. If your refactored code is worse than the original, I feel like you're doing something wrong.
- letitbeirie 6y agoRefactoring can also leave the code better off while simultaneously leaving the business much worse off. Just ask Netscape.
- eska 6y agoMaking two teams compete like that is a horrible idea. Both teams know that no matter how hard they work, their work may be thrown away. I've heard horror stories like this in a post mortem about the development of Sonic 3D for Saturn back then for example. There were two teams tasked with making a sequel, and only the better one would be released. Management's idea was that it was supposed to be a flagship title and had to be good. Both teams worked themselves to exhaustion and almost everyone quit the company, the rest got fired due to failure.
- bluGill 6y agoEven if the above doesn't happen, it is hard to say what you learn from two teams. Maybe one team is worse. Maybe one team got lucky because the serious bug was 1 in a million and not found, while the other spent weeks tracking down a similar level of complexity bug that happened every time and so had to be fixed... I can come up with more. The only thing fair is to give one team 6 months (ideally with a couple contractors who are experts to teach them best practices) to try the new thing. Less than 6 months and they are not far enough along the learning curve to make any useful statements. If you want a work done comparison you need to give half your teams (minimum 20 teams, ask a statistician for more details if you want to go lower or could go higher) that 6 months, and then after that give them a year to use the new one in real work, and compare that final year.
- nickelcitymario 6y agoTotally fair @eska and @bluGill. I really wasn't thinking in terms of "This is the right way to manage a project." I was simply trying to identify some way to do a better and more accurate comparison between Rust and C++. You're perfectly right that it would be awful to be pitched against each other in this way. So I recant my suggestion, but maintain my critique about using lines of code in a single project as somehow validating a language choice. There are too many variables. And, more to the point, the refactored code will almost always be much better, regardless of the language selected.
- dan_quixote 6y agoDeathmatch programming doesn't sound very pleasant. But I hope most people here don't feel a morale hit when their code gets tossed. Inherently, I understand the desire for one's creative work to live on, but that's essentially incompatible with this industry. And I also have found much joy in turning-down/deleting existing services I've written. My team celebrates these events and it's always fun to give that high-maintenance service a viking funeral.
- tyingq 6y agoIs there a comparison of Stylo to the Chromium/Blink equivalent somewhere? Performance, complexity, etc?
- tinus_hn 6y agoHave there been security issues in Stylo?
- stjohnswarts 6y agoActually that's a really good question :) . I would be interested if Rust's vaunted security advantages panned out. I know anything can have bugs but still it would be interesting.