10 ms·
Mozilla 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 struct
by KwanEsq 6y ago
Mozilla 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?
- dmos62 6y agoThe quote says that a parallel CSS engine in C++ was hard to get right in their case.
- skohan 6y agoThe post's claim is: > C++ simply wasn't usable for writing a parallel CSS engine. That's a stronger claim than that C++ was hard to get right. It's a claim that the language is not up to the task.
- bzbarsky 6y agoWhen the time cost of getting it right and _keeping_ it right exceeds the amount of time actually available in a day, the result is equivalent to "the language is not up to the task". I mean, you can implement anything you want in assembly, in theory. In practice, the cost of iteration tends to be high enough that implementing things with somewhat rapidly changing requirements (which includes CSS, to be clear!) pretty much requires a language in which iteration and refactoring can be done more quickly than in assembly. Maybe the confusion on your part is that you think "CSS" is a static set of requirements, so if you put in enough effort to implement it once you're then done? Unfortunately, that's not how it works in practice.
- skohan 6y agoThe fact that we disagree does not imply "confusion on my part". > When the time cost of getting it right and _keeping_ it right exceeds the amount of time actually available in a day, the result is equivalent to "the language is not up to the task". Again, this is referring to the particular approach that the Mozilla team took to the problem. If anything, one of the most valid criticisms of C++ is that the API is too large, and it has too many tools to work with at the expense of clarity. C++ allows you to express just about anything, and I do not think the standard of evidence has been met that the problem of writing a CSS engine could not be expressed in C++ in a way which would be both performant and maintainable. C++ has been used for many complex, high-profile projects which are widely used. There is nothing magical about CSS which creates problems C++ is incapable of solving.
- deleted 6y ago[deleted]
- skohan 6y ago> C++ simply wasn't usable for writing a parallel CSS engine. I think it can be said that Mozilla was able to use Rust to achieve what they failed to with achieve with C++. It's not justified to claim that C++ is/was not suitable for this purpose. C++ offers direct, low-level control over memory, and C++ can be used to implement anything which can be implemented in Rust. Maybe Rust has certain advantages which made this problem a lot easier to solve for Mozilla, and I'm certainly happy to have Rust in the language landscape, but another team with other processes may have been able to use C++ to achieve similar goals.
- dralley 6y agoA steak knife makes a poor scalpel but with enough effort you could probably perform a kidney transplant with one. It would just take 5 times at long and the patient would be at serious risk of bleeding out the entire time. You could in theory write the CSS engine in assembly too. A theoretical team, somewhere, could probably manage it. But given better options, it is not a reasonable thing to do.
- fpoling 6y agoThe biggest advantage of Rust is that the liner types and the borrow checker forces one to structure the application in a way that is much more manageable long-term and less error-prone even with occasional sprinkle of unsafe code. Surely one can code in such style in C++, but it is very unnatural there with a lot of boilerplate, so one just would not consider it typically.
- Mikhail_K 6y ago> Mozilla already tried re-writing the CSS engine in C++ before. They failed Blaming the tool for own failure to do the job isn't all that persuasive. > C++ simply wasn't usable for writing a parallel CSS engine. It might be not so much the proof of C++ deficiency as simply another manifestation of mismanagement of the browser development by Mozilla Foundation. > But Rust’s fearless concurrency has made parallelism practical!" Because nobody ever wrote concurrent systems in C++?
- monopoledance 6y agohttps://en.wikipedia.org/wiki/Russell%27s_teapot https://en.wikipedia.org/wiki/Russell%27s_teapot
- Mikhail_K 6y ago> Because nobody ever wrote concurrent systems in C++?
- wtetzner 6y ago> Blaming the tool for own failure to do the job isn't all that persuasive. I would argue it is persuasive if switching to a new tool lead to success. What would be the point of continuing to try the thing that's not working?
- viktorcode 6y ago> They failed. C++ simply wasn't usable for writing a parallel CSS engine. WebKit has CSS engine is written in C++. Chromium has one too.
- steveklabnik 6y agoIt’s not currently parallel though, right? That part is critical to the point being made. After all, Gecko had a C++ implementation too. Nobody is suggesting that any implementation is literally impossible.
- dralley 6y agoAnd Firefox had one too. But it wasn't parallel. That's what is being discussed here.
- stjohnswarts 6y agoIt it could be written in rust then it could absolutely be rewritten in C++ as well, especially if it was already written in C. That said I find doing concurrent/async programming much more enjoyable/quicker in rust. Too bad it's not as widespread as c++.