Multi-process
Firefox is fast like other browsers, but won’t suck up memory and slow
down your computer as Chrome will sometimes do.
Today Mozilla is releasing a new version of Firefox
that runs using a multi-process architecture, for the first time using
several separate processes for your web page content (your tabs).
Now,
you might know that some other browsers have done this sort of thing
for a while. But even if you think you know everything about
multi-process browsers, or if you don’t have the first clue, read on.
In
this post I’ll explain what it means for Firefox to run with a
multi-process architecture. I’ll also explore how and why Firefox’s
approach to running with multiple processes is a bit different
from — and often better than — other browsers’.
As I considered how to explain something pretty technical, I thought about a story I frequently read to my daughter Sara: Goldilocks and the Three Bears .
How the Goldilocks principle manifests in web browsers
Much as astronomers search for a Goldilocks planet with life ,
Mozilla strives to build the Goldilocks browser. In my view, none of
today’s browsers strikes the “just right” balance between speed and
memory usage.
Your
browser’s use of memory impacts your experience both with the browser,
and with the other apps that you’re running on your computer. If a
browser uses too much memory, your computer may not have enough left to
the run the other apps you want to use. In fact, your computer may slow
to a crawl if you try to do too much.
Conversely,
if a browser doesn’t use much memory, it might not be doing some of the
things that it could to make your browsing experience fast and fluid.
The Goldilocks principle suggests that the “just right” browser is one
that uses a moderate amount of memory — enough to run quickly, but not
so much it exhausts your computer’s resources.
Your web browser often consumes more memory than any other app. If it uses too much memory, you might run out, and your whole computer will slow down.
An app’s ingredients
“Mama Bear’s Porridge” combines two ingredients: oats and powdered milk. Apps have ingredients, too: processes and threads.
When
you launch an app, it starts a process. This process can start many
threads of execution, each of which shares the same working memory.
Processes commonly utilize threads to handle different types of work
that need to run at different levels of priority. For example, one
high-priority thread may draw the program’s user interface. So the
browser knows this and will respond instantly to mouse clicks or typing
on a keyboard. Another thread may crunch data in the background at lower
priority. To see the processes running on your computer, open your Task
Manager (Windows) or Activity Monitor (macOS).
Sometimes,
instead of starting a new thread to accomplish a task, an app’s process
will start another process for that work. This makes sense for tasks
that requires a lot more memory and computing power, or for work that’s
better off isolated for security or stability reasons.
Most apps run in a single process, often using multiple threads. But web browsers are not like most apps.
Most apps use one process to run many threads, but browsers work best with multiple procesess.
Warm and tasty: the multi-process browser for the modern web
After
launching Firefox in 2004, Mozilla and its community continued to push
the web’s capabilities forward. Slowly but surely, the web became a
platform, not just for static documents, but for interactive apps like
email, word processing, and social networking.
Welcome to Web 2.0!
While
this new era of the web was wonderful, Firefox and other browsers
couldn’t run multiple web apps simultaneously nearly as fast as the
operating system could run native apps. The solution? The browser itself
needed to work more like an operating system, juggling several web apps
using multiple processes.
With
a multi-process architecture, you could use seamlessly a web page in
one tab, while pages in other tabs might still be busy crunching. While
Mozilla’s engineers knew that this new multi-process approach was
possible, adapting Firefox to run in multiple processes would require
breaking Firefox Add-Ons that depended on a single-process architecture.
Mozilla was reluctant to do this because customizing Firefox through
Add-Ons has always been very popular. My former colleagues who created
Chrome deserve credit for building it as a multi-process browser.
Enter Electrolysis: Mozilla’s project to split Firefox into multiple processes
It
was a long road to establish how Firefox should support Add-Ons that
would live in harmony with a multi-process architecture. Ultimately,
Mozilla committed to two related projects: (1) Electrolysis, an effort
to split Firefox into multiple processes, and (2) the transition from
traditional Add-Ons to cross-browser WebExtensions. Both initiatives
have been huge engineering efforts.
In August 2016, Mozilla launched the first phase of Electrolysis
by splitting Firefox to run its user interface and web page content
(the pages in your tabs) in two separate processes. Today Firefox is
shipping the next big phase of Electrolysis, significantly expanding the
number of processes Firefox uses for processing and securing web page
content, and enhancing the management of those processes to improve
memory use, performance, and stability. These additional processes can
potentially run across multiple computing cores, so it’s much less
likely for web pages to negatively impact each other or the performance
of the web browser in general. And, if a content process crashes, it
should not affect other content processes and the web pages displaying
in them.
The upshot of these changes is that Firefox is now faster and more stable than ever.
Why Chrome gets too hot when Firefox does not
While
both Firefox and Chrome now run using multiple processes, Firefox does
some things differently to avoid using up your computer’s limited
memory.
By default, Chrome creates a separate content process for each instance of a site
that you visit. Open 10 different tabs with 10 sites in Chrome, and
you’ll have 10 different processes. Each of those processes has its own
memory — with their own instance of the browser’s engine. One open tab
in Chrome typically consumes hundreds of megabytes of RAM. Chrome’s
liberal approach to creating processes can lead to very high memory
usage.
On
the other hand, Firefox’s more conservative approach to using processes
often results in Firefox using less memory than Chrome. By default,
Firefox now creates up to 4 separate processes for web page content. So,
your first 4 tabs each use those 4 processes, and additional tabs run
using threads within those processes . Multiple tabs within a process share the browser engine that already exists in memory, instead of each creating their own.
Chrome uses a separate content process and engine for each website instance, but Firefox reuses processes and engines to limit memory usage.
Comparing Firefox’s memory usage with other browsers’
Firefox
uses 4 content processes because it’s the “just right” number for many
Firefox users. With 4 content processes, your computer should have
plenty of memory left to run apps besides Firefox.
Windows 10 — Chrome used 1.77X memory as Firefox (64-bit), and 2.44X as Firefox (32-bit)
macOS — Chrome used 1.36X memory as Firefox (64-bit)
Linux — Chrome used 1.42X memory as Firefox (64-bit)
Firefox uses less memory than other browsers. Especially
if you’re using a laptop with 8GB of memory or less, you’re going to
want to think consciously about which web browser you use. Firefox’s
considerate usage of your computer’s memory means you can browse the web
freely, while still doing the other things you need to do with your
computer. If you have more than 8GB of RAM, you might want to
bump up the number of content processes that Firefox uses. This makes
Firefox even faster, although it will use additional memory. To change
the number of content processes FIrefox uses, enter about:config in your
address bar, and adjust the number for the dom.ipc.processCount setting
(we’ll be exposing a visible preference for this in an upcoming
release). Firefox’s new multi-process architecture is a major
step forward, and strikes an excellent balance between speed and memory
usage for many people.
Project Quantum: cooking up the “just right” browser for modern computing
As
proud as Mozilla is of today’s launch, its position is that no browser,
including Firefox, is truly “just right” for modern computers — at
least not quite yet. So much has changed inside of today’s devices, and
no browser has evolved to take full advantage of multi-core CPUs and
GPUs. So, while Electrolysis splits Firefox to run in multiple
processes, Mozilla’s other big project, Quantum , is optimizing the browser engine that runs within a content process. With
Quantum, Mozilla is building breakthrough enhancements to advance
Firefox in unique ways. As part of the project, Mozilla engineers are
using Rust to code super-fast
parallel algorithms that would be incredibly difficult to code safely
with C++. With these algorithms, major pieces of Firefox’s engine (e.g.
CSS styling), will run in parallel across multiple CPU cores, instead of
sequentially on one core. Also as part of Quantum, Firefox will utilize
threads to focus computing power and your network connection on the
tabs you’re actively using. Firefox will get much faster, while still
being respectful of your memory and your needs. I hope that you enjoy today’s Firefox release
and that you stay tuned for the Quantum leap ahead. Mozilla’s goal is
to make Firefox the “just right” browser for every computer, for
everyone. Source:
https://medium.com/mozilla-tech/the-search-for-the-goldilocks-browser-and-why-firefox-may-be-just-right-for-you-1f520506aa35