How web browsers use Process & Threads-Chrome & Firefox
Before talking about our main topic we need have an idea about what is a web browser. A web browser,commonly referred to as a browser is a software application for accessing information on the World Wide Web. When a user requests a web page from a particular website, the web browser retrieves the necessary content from a web server and then displays the page on the user’s device.
Process and Threads????
A process can be described as an application’s executing program. A thread is the one that lives inside of process and executes any part of its process’s program.
When you start an application, a process is created. The program might create thread to help it do work, but that’s optional. The Operating System gives the process a “slab” of memory to work with and all application state is kept in that private memory space. When you close the application, the process also goes away and the Operating System frees up the memory.
Web Browsers vs Other Applications
So now we have an understanding about browsers,threads and processes let jump in to our main topic “How browsers use threads and processes”.
When we launch an normal application,it’s starts a new process.And inside this process we have many threads which executes sharing the same working memory.But compared to normal application,modern web browsers works differently.Instead of using multiple threads inside a single process,browser’s process will start another process for that work.Chrome used this multi process architecture from the beginning while older versions of Firefox the entire browser ran within a single operating system process.But from early 2017 Firefox started using the multi process Architecture.
Chrome Browser Architecture
Chrome executes few separate processes like Browser Process, Renderer Process,Plugin process,GPU process,Extension process and utility processes while the execution.
Each type of process controls a different task.
- Browser Process : Coordinating with other processes that take care of different parts of the application
- Renderer Process : Controls anything inside of the tab where a website is displayed.
- Plugin process : Any plugins used by the website, for example, flash
- GPU process : Handles GPU tasks in isolation from other processes.It is separated into different process because GPU handles requests from multiple apps and draw them in the same surface.
Firefox Browser Architecture
With the introduction of multi process architecture to Firefox, it 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 vs Firefox
Since now we know how Chrome and Firefox use processes and threads Let’s talk about how it affects the memory usage,speed and security.
As we know chrome creates a separate process for the every site you visit.Each of those processes has its own memory with their own instance of the browser’s engine and it will typically consumes hundreds of megabytes of RAM .Since that Chrome uses very high memory space.
In chrome if you open 10 different tabs it will create 10 separate processes but in Firefox since it only creates up to 4 separate processes it will create those 4 processes and additional tabs will run using threads within those processes.So compared to Chrome,Firefox will consume less memory.
Since the high memory consumption of chrome the remaining memory for other apps decreases. So it will sometimes lead your computer to slowdown as well.
Apart from memory usage and speed,secure browsing is also really important. Since operating systems provide a way to restrict processes privileges, the browser can sandbox certain processes from certain features. For example, the Chrome browser restricts arbitrary file access for processes that handle arbitrary user input like the renderer process.So the chrome browser architecture will provide little bit more security for you while browsing.
References
- https://medium.com/mozilla-tech/the-search-for-the-goldilocks-browser-and-why-firefox-may-be-just-right-for-you-1f520506aa35
- https://developers.google.com/web/updates/2018/09/inside-browser-part1
- https://www.extremetech.com/internet/250930-firefox-54-finally-supports-multithreading-claims-higher-ram-efficiency-chrome