The Parallel Future Of The Browser

Fresh like chrome was we had a bumpy road we were starting with this existing code base which was developed before multi-core architectures were common and we needed to figure out how to break apart this codebase without breaking anything for our users.

While we were doing it so we needed to plan for that but we didn’t just stop and making plans for this.

Coarse grained parallelism we saw that we were going to need to take it further because when you have this kind of course brained parallelism there’s a good chance that you’re still not making the best use of all of your cores thank you thank you for.

Reminding me where I was so we thought we were gonna take it further because when you have this kind of coarse grained parallelism there’s a good chance you’re still not making good use of all of your cores of all of the hardware that’s in your machine for example you might have one tab that’s doing a whole lot.

Of work but the others might not be doing much work at all that means those other cores are.

Sitting idle so you’re not getting the kind of speed up that you could get from a parallel architecture we saw that if we wanted to make a browser that was really fast we couldn’t just add this coarse grained parallelism we needed to add fine grained parallelism too so what is fine grained parallelism well that’s when you take one of these big tasks and you split it up into smaller tasks.

These can be more easily split up across.

The different brains so across your different cores but that does usually mean that you’re gonna have to share a memory between the cores and you know this opens you up to those data races that I was talking about before these data races are nearly impossible to avoid when you’re sharing memory and they’re incredibly tricky.

To debug the thinking at that time was basically that to safely program in parallel you had to have kind of a wizard level understanding of the language that you were working in one of the distinguished engineers at Mozilla actually put a sign about eight feet high and said you must be this tall in order to write multi-threaded code now of.

Course when you have a project like an open source browser where you have thousands of contributors we’re adding code to the codebase you can’t code in a way that requires a wizard level understanding of the language if you do you’re going to run into these data races for sure and these data.

Races and other memory issues cause some of the war security vulnerabilities and browsers so if we wanted.

To take advantage of this fine grained parallelism without the peril that these data races introduce we couldn’t just start hacking a parallel browser we had to find a way to make it safe to do that so rather than starting a.

Project to rewrite the browser we started sponsoring a project to create a new language to write that browser in this language is the rust programming language as part of its design and make sure that these kinds of data races can’t.

Happen if you have code that wouldn’t.

Introduce these data races to your codebase it just won’t compile we started sponsoring work on rust around 2009 or 2010 it wasn’t until 2013 that we actually started putting it to use in a browser though you know we started seeing whether or not it could create the browser that we wanted I don’t know if any of you have.

Heard of the term hack shaving where you have to do one seemingly unrelated task before you get to the thing that you really meant to do but at Mozilla we have some pretty big yaks to shave so in.

2013 with this language in hand that allowed us to code in parallel without fear we started looking at how we could really introduce fine grained parallelism into the browser.

The project that we started to do this is called servo we started by looking at the rendering engine pipeline and asking what happens if we paralyze all of the things this means we’re not just sending the different content windows to different with different pages.

To different cores we’re taking a single content window and splitting up the different parts of that page that means if you have a site like Pinterest each different.

Pinned item can be processed separately from the others for example for CSS you could send each pinned item to get a CSS filled out by a different core this means that you can speed up different parts of the rendering pipeline by however many cores you have which means that as chip manufacturers add more cores into the future these pages are going to.

Get faster and faster automatically this is the key this is why fine.

Grained parallelism is so important and this is why we spent so much time and risked so much in pursuing it because it wasn’t clear at the start of this project that it was actually going to work coarse grained parallelism is pretty straightforward but this fine green parallelism creating a language that made it safe and.

Then implementing it in a browser that was a tough research problem but that time and effort is paid really paid off we found out that these ideas work and that they work really.

Well over the past year we’ve started bringing pieces from servo into Firefox so we’ve been doing this as part of project quantum which is a major speed-up of firefox that we’ve.

Been working on for the past year it’s kind of like replacing the different parts of a jet engine mid-flight one thing that we brought over is are parallel style engine called stylo that splits up all of the CSS processing across the different CPU cores.

As I mentioned before it uses a.

Technique called work-stealing split up that work whenever a core runs out of work it can still work from the other cores and this makes splitting up work efficient and makes it possible to speed up CSS style computation by however many CPU cores you have another piece that.

We’re bringing over is called web.

Render web render takes the painting composite stages and combines them into a single rendering stage it uses the hardware in a smart way to make painting the pixels faster which means it can.

Those larger displays to do this it uses another highly parallelized part of the computer which is specifically meant for graphics this is called the GPU or the graphics processing unit the cores on the GPU are a little different from the cores on the CPU instead of having two or four six of them like.