process

When we start a program, the operating system allocates space for the program to store the code to be executed, the data to be executed, and a main thread to execute the task. We call this environment a process.

  • Thread is attached to the process, and the use of multi-thread parallel processing in the process can improve the efficiency of computing.
  • An error in any thread of the process will result in the failure of the entire program.
  • Threads share data in a process.
  • When a process is shut down, the operating system reclaims the memory occupied by the process.
  • Each process is isolated from the other.

Problems with single-process browsers

A single-process browser means that all of its module, browser rendering, and JS code execution are in the same process. As a result, one mistake can cause the entire process to fail.

  • Is not stable. (Rendering engine modules and plug-ins are unstable, causing the entire browser to crash)
  • Not smooth. (Page memory leaks make it easy for code to slow down at complex points.)
  • Not safe. (Any resources of the operating system can be obtained through plug-ins)

Multiprocess browser

  • The plug-in, page rendering, and browser main processes are all done in separate processes. Processes do not affect each other, and the crash of one module does not affect other modules. Solved the problem of instability.
  • Since each rendering is done in a separate process, when one page gets stuck in an endless loop and a lot of memory leaks, you can just close the entire page without affecting the rest of the page, thus solving the problem of poor flow.
  • With multithreading, a secure sandbox can be used. Programs run in the sandbox, but malicious programs cannot break through the sandbox to gain access to the system.

Current multi-process architecture

The latest Chrome browser has five processes: one main browser process, one GPU process, one web process, multiple rendering processes, and multiple plug-in processes.

  • Browser process. It is mainly responsible for interface display, user interaction, sub-process management, and storage.
  • Render process. The core task is to turn HTML, CSS, and JavaScript into web pages that users can interact with. Both the typography engine Blink and JavaScript engine V8 run in this process. By default, Chrome creates a rendering process for each Tab Tab. For security reasons, renderers run in sandbox mode.
  • Process of GPU. In fact, Chrome didn’t have a GPU process when it was first released. The original intention of using GPU was to achieve 3D CSS effect, but later the UI interface of web page and Chrome were drawn on GPU, which made GPU become a common requirement of browser. Finally, Chrome has introduced GPU processes on top of its multi-process architecture.
  • Network process. It is responsible for loading web resources on the page. It used to run as a module in the browser process until recently, when it became a separate process.
  • Plug-in process. It is mainly responsible for the running of plug-ins. Plug-ins are prone to crash. Therefore, plug-ins need to be isolated through the plug-in process to ensure that the plug-in process crash does not affect the browser and page.

Disadvantages of multi-process browsers

  • Higher resource usage.
  • More complex architectures. High coupling between browser modules, poor scalability and other problems will lead to the current framework is difficult to meet new requirements.