I often see delays of ~10 seconds between two ScreenshotRunnables running, even though gecko isn't doing anything else in between. It looks like calling MessageLoop::current()->PostIdleTask doesn't wake up the message pump that may be sleeping in NS_ProcessNextEvent. This means if a whole bunch of ScreenshotRunnables get queued up, they may not get run during actual idle periods, and may only trickle out as various background timers fire. Another related problem is that the loop in MessagePump::Run should have a "continue" statement if DoIdleWork() returns true, so that it can process multiple pieces of idle work before going back to sleep.
Created attachment 635048 [details] [diff] [review] Allow processing multiple pieces of idle work in a row This fixes the second part of the problem (not processing more than one idle work in a row), and is sufficient for the screenshot code. However it would be good to also fix the other problem (that of queueing idle work not waking up the message pump).
Pushed to try: https://tbpl.mozilla.org/?tree=Try&rev=7724a9f20832
Try run was pretty green, so landed on inbound: https://hg.mozilla.org/integration/mozilla-inbound/rev/5bd5734369f7