Off Main Thread Compositing (OMTC) and why it matters

Like most desktop applications, Firefox is driven by an event loop. Currently this event loop is servicing a lot of events including page layout, drawing, image decoding and don’t forget JS. We do our best to handle events quickly (in a few milliseconds) and break up the ones that we know will take longer (such as image decoding). Any event, such as poorly written JS, that takes too long to process will cause the application to feel sluggish and will cause updates, animations and videos to pause.

Every web page is broken into a set of layers (backgrounds, canvas, video, web contents, position fixed element, elements that are being animated) by our layers system. When these layers are updated they must be flattened to the screen to show a final frame. This process is called ‘composition’. Currently this composition is driven by the main event loop. While compositing does add more load to the event loop from my experience the load it adds is often negligible. After all with hardware accelerated layers backends the work is mostly just queuing a few simple graphics command to the GPU.

Simplified painting pipeline (Desktop Current)

So why move compositing to a second thread if it’s relatively cheap? Because we need the event loop to be responsive to service composite events and any slow events (>15ms), such as a long JS script, will cause us to drop frames. By compositing on a separate thread we can still service layers update and keep the browser partially responsive even if the event loop is momentarily blocked by a long running script.

Simplified OMTC painting pipeline (Fennec Beta)

There is one catch however. If the main event loop is being hogged by an event then that will block certain updates, like page reflows, from reaching the compositor. However other types of updates can still be made while the main event loop is bogged down such as video which we decode in yet another thread, css/gif animations and plugins to name a few. Another use case is to support smooth panning and zooming on mobile. The goal we’re aiming for is to make Firefox more responsive.

The feature just shipped into the latest Fennec beta and provides a smoother experience while consuming less resources.

Simplified OMTC painting pipeline (Desktop/Fennec Future)

In the future we plan on landing more changes that will leverage this new architecture. We are considering many proposal shown above. Some are uncertain at this point such as having canvas workers. Right now our current focus is passing decoded video frames directly to the compositor and handling simple CSS animation asynchronously. These features will allow video and animations to perform smoothly over short periods of blocking similar to async scrolling on Fennec. We’re hoping to have some of these features landed in Q2 for mobile and desktop where OMTC will likely still be behind a preference until later this year. Stay tuned to these bugs to try out these features when they land.


34 thoughts on “Off Main Thread Compositing (OMTC) and why it matters

  1. Pingback: Native Firefox for Android Beta |

  2. Pingback: GFX Changes in Firefox 13 « Benoit Girard's Blog

  3. Pingback: Splitting up the work for the UI thread | FunctionSource Development

  4. Pingback: Mobile Firefox: Measuring How a Browser Feels | William Lachance's Log

  5. Pingback: Video Synced Profiling « Benoit Girard's Blog

  6. Pingback: Multiprocess Firefox | Bill McCloskey's Blog

  7. Pingback: Firefox for Android in 2013 | Lucas Rocha

  8. Pingback: Firefox 33 Find out what is new - gHacks Tech News

  9. Pingback: Lucatarik | Firefox 33 Find out what is new

  10. Pingback: Firefox 33 on julkaistu – täältä saat sen heti ladattua -

  11. Pingback: Firefox 33 on julkaistu – täältä saat sen heti ladattua | Iltapuuro

  12. Pingback: Firefox 33 arrives with OpenH264 support, sending video to Chromecast and Roku from Android | 381test

  13. Pingback: Firefox 33 ya disponible con WebRTC y streaming en Android

  14. Pingback: Релиз Firefox 33 | — Всероссийский портал о UNIX-системах

  15. Pingback: Mozilla Firefox 33.0 正式发布 爱玩软件 | 爱玩软件

  16. Pingback: Firefox 33 Find out what is new | vpsdash

  17. Pingback: Navegadores Firefox 33

  18. Pingback: Firefox 33 arrives with OpenH264 support, sending video to Chromecast and … – VentureBeat | Best electronic online

  19. Pingback: Firefox 33 steht zum Download bereit | Software news

  20. Pingback: Firefox 33 Find out what’s new | Windows8to9

  21. Pingback: SeaMonkey 2.30 est sorti » MozillaZine-fr

  22. Sounds good tho complicated. I tinkered with a related tho far simpler coding problem on a Commodore years ago to get a homemade text editor to achieve snappier performance without glitches, running the main program thread and the interrupt thread handling the keyboard. Two other sources of slowness not mentioned in this article are network delays and either thrashing or cache cleaning. While the program is waiting on a network response, and waiting, and waiting, it could be doing something useful instead of constantly checking for the network response in a tight loop. By the way, the stop-key testing should be in those tight loops so it will actually stop an attempted action. If the cache exceeds the max, the program stops and cleans the cache, when it would make a lot more sense to wait until program exit to downsize the cache or at least until a time of low total system activity.

  23. Pingback: Firefox 33.0.1 behebt Darstellungsprobleme | Software news

  24. Pingback: Firefox 33.0.2 behebt Absturzprobleme | Software news

  25. Pingback: Firefox 33.0.2 behebt Absturzprobleme | WorldNews

  26. Hmm – I am struggling since longer which browser could be used reasonable and I can’t find any right now. Since Seamonkey took over the chrome engine we are facing as “experienced” users a lot more data shuffling which is really annoying.

    I am doing very much research work on internet worldwide – non paid ones for some personal reasons – and since a couple weeks I found myself much more often suddenly freezed with either browser, especially after the latest updates, which are now coming on a weekly basis, what made me thinking “What are in heavens name all these programmers are doing???”, because I never had this occurrence that often before.

    Now reading your well written explanations gives me all of a sudden a much deeper insight into such complicated structure of internet “events” which must be handled within milliseconds and where we all know you will reach sooner or later the end of what is possible to code or else our machines won’t be able to manage so much data in time – no matter how many threads the cpu-s are providing – but that’s another technical subject.

    Now – as a very “old” former programmer in midrange systems I can’t give you a great discussion on the new programming techniques but I know well how systems create their own “life(cycles)” and no one is able to control what comes out that at the end. This is greatly proven on the new software design we got in the late 80ies called “object orientated programming” – creating millions of little boxes we had earlier in so called sub-routines placed or even only physically read tables. So since then the “dumbness” of programmers increased terribly as they have only been educated how to use the modules and new languages but no idea ever where this or that inconsistency may come from or it was prohibited to remove such as of patents rules – right??

    In my opinion you should not follow all the rules coming from “outsiders” which are mostly made up by such global players as GOOGLE and Co. supporting only their business goals. Because this is a permanent hassle against time and you can’t win, namely using now the chrome engine which is set up into all most famous browsers.

    Looks to me more likely that all free software groups have lost a big fight….???

    Fact is – Google and some other companies are aiming for the paid only internet and since longer they all make us pay for their loads twice as much as we did some years ago. What does that mean? Very simple said – all the ads coming up and down are paid by “us”, the customers of providers. So providers are making billions every year on that kind of indirect business and no one stops them from doing that. And I know that this could be done…

    Under such circumstances I must put the question what “free” software really implies today???

    If some programmer groups really want to achieve a new respect worldwide they should be able to filter the whole protocols and data streams under their control.

    But maybe that is prohibited…as no one ever discussed this basic problem of a closed up internet for only business and no more open to be used for information and/or information exchange of individuals.

    So I am initiating this question to you as representative of one important group of free software designers.

    If free software groups like FSF can’t win this struggle we will be trapped in a few years in a super controlled world – and not only in internet but everywhere.

    The 1984 story is far beyond from what we have already – and I am really wondering why no one of you is ever considering the consequences if you will continue to follow up all together like lemmings the rules made up by business goals only?

    But maybe someone could give me a more positive view into future…???


    2014-12-06 – E. A l b u s

  27. Pingback: Релиз Firefox 33 | FNIT.RU

  28. Pingback: FIX: FireFox Black Page Rendering Problems » UserHaven

  29. Pingback: Co nového přinese Firefox 33 |

  30. Pingback: Mozilla veröffentlicht Firefox 33 für Desktop –

  31. Pingback: Software Update: Mozilla Firefox 33.0.2 - TechWarrant

  32. Pingback: Software Update: Mozilla SeaMonkey 2.30 - TechWarrant

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s