Responsiveness for Plugins and the Renderer
Friday, October 10, 2008
In my last post, I wrote about how we handle I/O in the browser process to keep the main thread of Google Chrome free from hiccups. This time, I'll write about how we keep our sub-processes from interfering with the main ("browser") process.
As you may recall, Google Chrome is a multi-process application, with HTML rendering happening in separate processes we call the "renderers," and plugins running in separate "plugin" processes. Our priority is to always keep the browser process, and especially its main thread, running as smoothly as possible. If a plugin or renderer is interfering with the browser process, the user's interaction with all other tabs and plugins, as well as all the other features of Google Chrome, would also be interrupted. The user might even be prevented from terminating the offending sub-process, negating a key benefit of our multi-process architecture.
The first and most obvious approach is never to block while waiting for information from a renderer process, in case the renderer process happens to be busy or hung. And although the renderers may sometimes synchronously wait for the browser for some requests, there is not an easy way to express that the browser process should wait for the renderer on Windows. Unfortunately, this doesn't cover all cases.
The basic primitive of Microsoft Windows is the "window," which is much more general than just a top-level window with a title bar. Buttons, toolbars, and text controls are usually expressed as sub-windows of a floating top-level window. Windows in this hierarchy are not restricted to single processes, and early versions of Google Chrome used this feature to implement our cross-process rendering architecture. Each tab contained a sub-window owned by a renderer process. The renderer received input and painted into its child window just like any other. The browser and renderer processes each ran their own message processing for things like painting.
A problem arises for some types of Windows messages. The system will synchronously send them to all windows in a hierarchy, waiting for each window to process the message before sending it to parent or child windows. This introduces an implicit wait in the browser process on the renderer processes. If a renderer is hung and not responding to messages, the browser process will also hang as soon as one of these special messages is received. To solve this problem, we no longer allow the renderers to create any windows. Instead, the renderer paints the web page into an off-screen bitmap and sends it asynchronously to the browser process where it is copied to the screen.
Once we made this change, everything ran great. That is, until we implemented plugins. The NPAPI plugin standard that Google Chrome implements allows plugins to create sub-windows, and for compatibility, we can't avoid it. Sometimes a plugin may hang, or more commonly, block waiting on disk I/O. All the hard work we did to insulate the user interface from I/O latency is occasionally undone by our plugin architecture through this long chain of dependencies. To mitigate this problem, we periodically check plugins for responsiveness. If a plugin is unresponsive for too long, we know that the user-interface of Google Chrome might also be affected, and the user might not even be able to close the page that is hosting the plugin. To allow the user to regain control of the browser, we pop up a dialog that offers to terminate the plugin.
If you are doing something that saturates your hard drive (such as compiling Google Chrome), now you know one of the reasons why the interface may occasionally hang and give the "hung plugin" dialog box. Sometimes you may not even realize that a page has loaded plugins when you get this message. You can terminate the plugin immediately, but most of the time it also works to just wait longer for the plugin's I/O to complete.

16 comments:
kirill said...
How often are plugins checked for responsiveness? I used to get the frozen plugin popup a few times in the past but now it can just sit there frozen for minutes with no popup...
October 10, 2008 3:02 PM
Brett said...
I believe they are considered hung after something like 30 seconds by default.
October 10, 2008 3:20 PM
Γριφεγ said...
When having multiple (2-3) tabs open which all have Flash ads, Chrome pauses for a few seconds while Flash loads. (Only when there are already other tabs with Flash.)
Unfortunately Flash is quite common and this makes Chrome feel a lot slower than say Opera, which doesn't exhibit this problem.
October 10, 2008 3:55 PM
Dying said...
October 10, 2008 3:57 PM
Dying said...
I find it hard to buy, sorry. I really wish it was true, but Google Chrome and plugins - are not getting along well. It gets stuck whenever the flash is too resourceful.
I hope it will improve quickly, because that is a really big low point.
Thank you for the amazing work you are all doing!
PhistucK
October 10, 2008 3:59 PM
Dying said...
By "stuck" I mean, you cannot even reach the task manager of Chrome.
PhistucK
October 10, 2008 4:01 PM
Electro said...
What Dying said...Chrome freezes on Flash. Otherwise, it would be my Number One browser.
October 10, 2008 8:24 PM
Joe said...
I'm conflicted. The speed of JavaScript Apps makes the browser seem like a breeze, but when working with Flash it can get to be a real pain. So far I am sticking with Chrome, but I suspect a lot of people will not be so forgiving.
October 10, 2008 8:27 PM
Yawar said...
Interesting idea with the off-screen bitmap painting. Is it possible to encapsulate a plugin in a layer where it thinks it's painting its own window but all its painting commands are being sent to an off-screen bitmap as well? A virtual window, I guess you could call it.
October 11, 2008 10:42 AM
Justin said...
Kinda offtopic, but I assume things like LibOS, exokernels (nee no kernel) and Stallman's ideal GNU OS (each user will have efficiently-multiplexed full bare-metal access to a sort-of distributed virtual machine) will solve this. Every app will have full control over it's own VM and i/o model. Now if I only knew what all those buzzwords actually meant! lol
October 11, 2008 6:53 PM
Brian M said...
Could you limit the plugin to a single window (tab)? That would allow us to install a plugin and run it from only a single tab.
I realize that most plugins would have to be modified, but...
October 13, 2008 5:51 AM
-RobW- said...
I am finding Chrome almost unusable for sites requiring either Flash or for reading PDF documents.
Flash is so ubiquitous I find my entire browser freezing accidentally if I open a new tab while reading that happens to contain a Flash app, and I effectively cannot scroll any PDF documents.
I certainly am not necessarily doing anything hard disk intensive; it happens pretty much every time, even if I am doing nothing but browsing.
It is so very quick for everything else I find myself getting disproportionately annoyed when this happens.
Surely if it was a problem with plugin architecture in general this behaviour would be exhibited on every other browser? Why is it not?
October 13, 2008 6:42 AM
nullstring said...
Hey guys, in my case, gChrome browser usually hangs when I watch videos in YouTube. Somebody from gChrome devs asked me about the hardwares specs, but of course that's understandable ... but JUST NOW, I found a quick solution for this hanging thing (accidentally actually) ... not really sure if this one works with you but hope it helps.
When gChrome starts to hog your CPU at full throttle (100%) just right click on gChrome button on taskbar, wait a few seconds and that's it, back at normal ... just keep doing the same thing..
October 19, 2008 9:42 AM
thydavidcome said...
I uninstalled my flash and installed the new version (version 10?) and now Flash is much more responsive, and much much much less hang ups
October 19, 2008 7:38 PM
Scott said...
To everyone complaining about the flash responsiveness: this is a problem that has been fixed for over a month in the dev channel; http://dev.chromium.org/getting-involved/dev-channel/
October 20, 2008 3:24 PM
Our Investment said...
Visit to my blog and get money, visit to http://globalnewsfinance.blogspot.com/ and http://majapahit.crazytomato.com/
October 22, 2008 6:30 PM
Post a Comment