Live data from Hacker News

Fearless Concurrency in Firefox Quantum

blog.rust-lang.org

141–150 of 177 posts

Re: Fearless Concurrency in Firefox Quantum

#141

Earlier quoted context omitted.

>> When an XHR response comes back as HTML, there is no "Preview" tab like in Chrome. > This is consolidated in the Response tab. You can view it as raw response, or JSON (with filtering options). Yeah, I can see the raw HTML or JSON response. But Chrome actually allows you to see the rendered HTML response in the "Preview" tab. Are you saying there is a way to see the rendered HTML from the XHR response? I'm not see…

Looks like this has been fixed now: https://bugzilla.mozilla.org/show_bug.cgi?id=1353319 If you grab Nightly (I've been using it for a year now for frontend development and my normal browsing and it's just fine) you can test it.

Switched to nightly and there it is. Thank you!

Re: Fearless Concurrency in Firefox Quantum

#142
post #45
post #8

I like this explanatory comment by Manishearth, a Servo dev, in the thread over on /r/rust: "This blog post brought to you by the 'how many times can you say 'fearless concurrency' and keep a straight face' cabal. "Seriously though, I now appreciate that term a lot more. One thing that cropped up in the review of this post was that I didn't have examples of bugs Rust prevented. Because I couldn't think of any concret…

I've spent the last few days aggressively parallelizing some Rust code with crossbeam, and it's really just... painless (once you're used to Rust). Rust actually understands data races, and it grumbles at me until my code is provably safe, and then everything Just Works. The Rayon library is also lovely for data parallelism. Sometimes, I think, "Rust is basically a nicer C++ with the obvious foot guns removed and gre…

> basically a nicer C++ with the obvious foot guns removed

For those stuck with C++, you're not out of luck in terms of safe and easy sharing between threads. The SaferCPlusPlus library provides "access requesters" that provide functionality and (data race) safety similar to Arc.

Unfortunately the documentation[1] is "in transition" at the moment and does not currently refer to the very latest version. But the main difference is that the latest version implements something akin to rust's "sync" trait to help prevent you from attempting to share inappropriate data types.

Again, documentation is a work in progress, but if you're interested you can check out an example that demonstrates an array being safely modified simultaneously from multiple threads[2].

[1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus#asynchronou...

[2] https://github.com/duneroadrunner/SaferCPlusPlus/blob/7e3574...

Re: Fearless Concurrency in Firefox Quantum

#143
post #66
post #14

Earlier quoted context omitted.

I'm a former C++ dev who went all in on Rust. I think the main problem is that the learning curve works in Rust's disadvantage here. If you start learning C++ it's relatively smooth sailing at first, especially if you're already familiar with C. Basic OOP, basic RAII, inheritance, virtual functions, basic templates. Easy peasy. It's once you start getting to the advanced topics that the footguns become apparent. The…

I hope there is a new language which combine "C++" + "thread safe and mem safe". That will be a killer language

There is. The name is Rust, I heard

Re: Fearless Concurrency in Firefox Quantum

#144

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.

Virtually no large scale C++ app has successfully consistently followed the safety rules. It is too easy to, for example, store references to the mutex-protected object somewhere and have those references persist past the unlock operation, allowing unsynchronized access. References and raw pointers are created invisibly in C++ (example: "this"), unlike in Rust where "unsafe" is always explicit (and can be forbidden with a compiler switch or source annotation).

Re: Fearless Concurrency in Firefox Quantum

#145

Earlier quoted context omitted.

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++.

That has empirically been proven false over a decade of C++ use. Additionally, C++ allows for plenty of memory safety problems without any syntactic ceremony.

Re: Fearless Concurrency in Firefox Quantum

#146

Earlier quoted context omitted.

"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.

> if it thinks it has a concurrency bug in it. This makes it sound like it is wrong sometimes. I'm not using Rust, if this is what you meant, could you give examples of that?

It would probably be more accurate to say "if it can't prove there aren't any data races".

Re: Fearless Concurrency in Firefox Quantum

#147
post #94

Earlier quoted context omitted.

> 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.

"quantum" doesn't mean "small". "quantum leap" means an abrupt, large, leap. See https://en.wiktionary.org/wiki/quantum_leap

It's a joke. A quantum leap is what you say, but a quantum in physics is all about being the smallest discrete unit of some physical property such as energy.

Re: Fearless Concurrency in Firefox Quantum

#148

Could someone give a very simple, to-the-point example of a kind of concurrency bug that Rust prevents, for those of us who don't know Rust? (The author explicitly fails to think of any, so I'm hoping someone else can. It'd be more convincing to see one.) EDIT: I meant a code example, not a paragraph. And I would obviously expect to see how the intended goal is achieved without the bug... otherwise it'd be trivial to…

Borrowing from https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.h... (linked to from the original post), the following code tries to access a lock-protected vector. fn use_lock(mutex: &Mutex >) { let vec = { // acquire the lock let mut guard = lock(mutex); // attempt to return a borrow of the data access(&mut guard) // guard is destroyed here, releasing the lock }; // attempt to access the data outside of t…

It's arguably even a little bit nicer in SaferCPlusPlus[1]:

    template
    void write_foo(TVectorPointer vec_ptr) {
        (*vec_ptr)[3] += 1;
    }
    
    template
    auto read_foo(TVectorPointer vec_ptr) {
        return (*vec_ptr)[7];
    }
    
    template
    void use_shared_vector(TVectorAccessRequester vec_ar) {
        {
            // obtain a non-const pointer to the vector from the "access requester"
            // blocking if necessary
            auto wl_ptr = vec_ar.writelock_ptr();

            write_foo(wl_ptr);

            // the pointer owns a lock on the vector so as long as the pointer
            // exists it is safe and valid to use
        }

        // obtaining and using a const pointer to the vector
        auto res1 = read_foo(vec_ar.readlock_ptr());
        
        // without a "lock pointer" obtained from an access requester, there is no way
        // to access, or even refer to the shared vector, so you can't access it in an
        // unsafe manner
    }
[1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus#asynchronou...

Re: Fearless Concurrency in Firefox Quantum

#149
post #131

Earlier quoted context omitted.

I kinda agree. A few key things missing in FF that I need: * selecting CSS colors in other colorspace (eg. RGBA) as oppose to just hex * throttling the network in desktop mode. I think the option just shows up in responsive design mode. Although I dont think Chrome is "vastly" superior at this point as FF has certainly narrowed the gap. > I've tried the Firefox inspect menu and I'm just immediately turned off and con…

> selecting CSS colors in other colorspace (eg. RGBA) as oppose to just hex I'm not sure if this is what you mean, but you can go into the dev tools config and change the default color unit under Inspector. The eyedropper will show values using the selected unit and style rules will be converted to that unit.

Whoa. I love FF even more.

Re: Fearless Concurrency in Firefox Quantum

#150

Earlier quoted context omitted.

Perhaps you're on an older version of FF, no? Because the things you mentioned are present, just not an exact UI/UX as that with Chrome. Im on FF Quantum 57.0 (non dev, vanilla FF) and here are my observations: > When an XHR response comes back as HTML, there is no "Preview" tab like in Chrome. This is consolidated in the Response tab. You can view it as raw response, or JSON (with filtering options). > Also, the res…

For XHR there's also an "edit and resend" button as well as "copy as cURL" which is amazing

copy as curl is so underrated
Post reply on HN