Live data from Hacker News

Fearless Concurrency in Firefox Quantum

blog.rust-lang.org

111–120 of 177 posts

Re: Fearless Concurrency in Firefox Quantum

#111

Earlier quoted context omitted.

Sure, the obvious example is your classic thead1 i++, thead2 i-- bug. In C you run each thread a large number of times in parallel and you end up with something other than 0. The solution is to use atomic operations or locks. Rust doesn't allow having two mutable references to the same memory location at the same time, so you would never encounter that.

> Rust doesn't allow having two mutable references to the same memory location at the same time, so you would never encounter that. Wouldn't that make a whole class of efficient algorithms impossible though? Like let's say you have an std::list and you want a sorted "view" of the elements. In C++ you'd create an array of pointers and then sort it, and after that you can just modify whatever each slot points to. In Ru…

You can do this with internal mutability. Mark the contents of the list nodes mutable by wrapping it in `Cell` or `RefCell`, and Rust will guarantee that any mutations still preserve memory safety.

Or, as Veedrac mentions, you can do it without any tricks if you can give up accessing the list itself while you have the array around.

Re: Fearless Concurrency in Firefox Quantum

#112

Firefox Quantum is blazing fast, and I finally ditched Chrome. My only problem is that it drains my battery life fast. So whenever I'm not plugged I use Edge. Other than that, FF is amazing. It is now my default browser and I even wrote a FF add-on a few days ago using their new API!

As a front end Dev I'll never fully ditch Chrome as its Dev tools are vastly superior. I've tried the Firefox inspect menu and I'm just immediately turned off and confused.. However Firefox has been, and always will be my daily driver for all Web browsing. It's eco system is richer, noscript and the fact that it's not a Google product is a huge selling point.

It is just a preference thing. I have always preferred FF tools over Chrome dev tools.

Re: Fearless Concurrency in Firefox Quantum

#113
post #94

Earlier quoted context omitted.

Agree about marketing. Mozilla needs to get the word out to those who don't follow the tech scene in any way, shape or form. That's the real challenge, but there also lie the bulk of its potential user base. Not sure exactly how they can do that without resorting to annoying, almost sleazy stuff that Google do (like bundling their browser with many other s/w and OEM system builders)... Quantum... I like to think of 5…

> quantum leap from before So, the smallest possible leap? :P I like to think that it's loosely related to the multithreaded work-stealing features, breaking as much as possible up into "quanta" of work to be grabbed by the next available thread. It's a decently memorable codename in any case, and works well enough for that purpose.

I think of it less as "the smallest possible" and more as just "one indivisible unit"- going from 56 to 57 without rewriting the style system in Rust would be a long and probably impossible task.

Re: Fearless Concurrency in Firefox Quantum

#114
post #93
post #7

> It replaces approximately 160,000 lines of C++ with 85,000 lines of Rust Wow! This is great, especially considering how bad and complex (in the bad sense) C++ is. Maybe Rust and Go will finally make the Frankenstein go to sleep

Is this reduction in line count typical? I'm surprised. Or is this discounting parts of the code that have been moved out into separate crates?

There's some good discussion of how it happened here: https://www.reddit.com/r/rust/comments/7cwpbq/fearless_concu...

One of the biggest contributors is "custom derive," which cuts out a lot of boilerplate. Another is that Gecko C++ is also pretty old and so doesn't rely on a lot of what is now standard. It's also just a ground-up rewrite, which has the advantage of hindsight.

It's not a trick of moving code around.

Re: Fearless Concurrency in Firefox Quantum

#115

Earlier quoted context omitted.

I'd love to know what this concurrency thing is and why it's so fearless in rust.

Here is a nice game about concurrency. It should answer your question why it should be feared by understanding how it works: https://deadlockempire.github.io/ As of my understanding it is fearless in Rust, because the problems that might came up are solved on language level or the compiler warns you about them. (I have never coded Rust, I just deduced this from the comments)

"Warn" is nicer phrasing than what the compiler actually does. Rust's compiler will straight up refuse to compile your code if it thinks it has a concurrency bug in it.

Re: Fearless Concurrency in Firefox Quantum

#116

Earlier quoted context omitted.

You can't implement it soundly.

Define "soundly". Follow the rules and it won't break. Will it break if someone memcpys some object internals or something? Sure. Just don't do that. The rules that make this abstraction robust in C++ are easy to follow, just like the rule that says "don't use unsafe" in Rust. Just like Rust, you can break the rule if you know what you're doing.

> Follow the rules and it won't break.

That's the problem here: you're on the honor system that everyone knows and follows every rule every time. Maybe you have a really top-notch team, great code review, etc. but can you say for a certainty that this will always be true, or that it's true of every bit of code you use?

Being able to prove that in advance, especially in more complicated scenarios, has a significant value from checking on every build, especially when you think of the many bugs which have been caused by maintenance code breaking some of the assumptions which the original authors had.

Re: Fearless Concurrency in Firefox Quantum

#117
post #5
post #3

Earlier quoted context omitted.

Rust only saves you from simple races, not more complex ones. That's quite a lot already. Most importantly, though, it preserves _memory safety_ in concurrent situations, so your stuff won't randomly crash, but properly panic. It's no silver bullet, but it _is_ the "magic sauce" behind Stylo.

I’m pretty sure Rust saves you from ALL data races so long as you stay within the boundaries of safe code. Do you have anything at all to reference otherwise that says only certain data races are detected while others are not? To my knowledge you can defeat the compile-time data race detection if you are either doing unsafe or certain scenarios with Cell/RefCell but even in that case you are guaranteed runtime detect…

Given the a "data race" is essentially defined to be the class of races that Rust's type system guards again, yeah it saves you from all of them.

Re: Fearless Concurrency in Firefox Quantum

#118

Earlier quoted context omitted.

You can't implement it soundly.

Define "soundly". Follow the rules and it won't break. Will it break if someone memcpys some object internals or something? Sure. Just don't do that. The rules that make this abstraction robust in C++ are easy to follow, just like the rule that says "don't use unsafe" in Rust. Just like Rust, you can break the rule if you know what you're doing.

You can't just wrap a statement the compiler has deemed to not pass the borrow checker and make it compile. Unsafe blocks can bypass the type system, but you have to call extra magic to do so.

Re: Fearless Concurrency in Firefox Quantum

#119
post #114
post #93

Earlier quoted context omitted.

Is this reduction in line count typical? I'm surprised. Or is this discounting parts of the code that have been moved out into separate crates?

There's some good discussion of how it happened here: https://www.reddit.com/r/rust/comments/7cwpbq/fearless_concu... One of the biggest contributors is "custom derive," which cuts out a lot of boilerplate. Another is that Gecko C++ is also pretty old and so doesn't rely on a lot of what is now standard. It's also just a ground-up rewrite, which has the advantage of hindsight. It's not a trick of moving code around.

Oh, thanks. Perfect link. It makes sense that rewrites are smaller, but the reduction factor was still surprising.

Re: Fearless Concurrency in Firefox Quantum

#120

Earlier quoted context omitted.

Define "soundly". Follow the rules and it won't break. Will it break if someone memcpys some object internals or something? Sure. Just don't do that. The rules that make this abstraction robust in C++ are easy to follow, just like the rule that says "don't use unsafe" in Rust. Just like Rust, you can break the rule if you know what you're doing.

You can't just wrap a statement the compiler has deemed to not pass the borrow checker and make it compile. Unsafe blocks can bypass the type system, but you have to call extra magic to do so.

So, really, what we're discussing is how much ceremony a language ought to require before enabling unsafe behavior. I think C++ provides enough ceremony that you can write decently safe programs in C++.
Post reply on HN