The upcoming Firefox 4 includes a ton of significant changes, many of which have a direct effect on add-ons. The majority of these changes are just new and different ways of doing things. Unfortunately, there are a couple of changes that offer no alternative and add-on authors will just need to cope with them. The stability changes that were introduced in the threading model for Firefox 4 are an example of this.
The Thread Manager was introduced in Firefox 3, and it appeared to work OK all the way up to recent Firefox 4 betas. This object allowed add-ons to run JS code on separate threads, pass objects to these threads and even access XPCOM objects within them.
It turns out that this was detrimental to the stability of the browser, and passing JS objects between threads would cause Firefox to randomly crash. When the cause of these crashes was found, the bug was fixed, irreversibly rendering the Thread Manager object fairly useless for add-ons.
Since a number of add-ons have been relying on the Thread Manager for some time, this change was quickly picked up by some authors and a discussion about it began shortly thereafter. The conclusion of this discussion is that there was no way the Thread Manager could allow passing JS objects again, and that the appropriate alternative was to use ChromeWorkers. At the moment of this discussion, a ChromeWorker was just the same as a Worker, with the only difference of being able to use js-ctypes to connect to compiled libraries. This wasn’t enough for add-ons, though, so the introduction of XPCOM in ChromeWorkers began.
This leads us to the current state of affairs: if you want to run code on a separate thread, our best recommendation is to use ChromeWorkers. They can now access XPCOM objects, as explained in the documentation, limited to components that have been marked as thread-safe. Because of this only a few components are currently accessible, and trying to use a non-thread-safe component will throw an exception right away.
This is as good as things will get in the Firefox 4 timeline, unfortunately. I’m already talking with the platform team about ways to make more XPCOM components thread-safe and therefore useable from ChromeWorkers. I’ve been looking at Thread Manager usage in add-ons listed on AMO, so I have a good idea of how add-ons were using these interfaces. The most frequent uses, like file system I/O will take precedence, and hopefully they will be included in whatever Firefox release comes after 4.
If you have an add-on that is affected by this change, I’m interested in knowing how you are/were using threads in your add-on. This can have an effect in future Firefox development, so please leave a comment.
Justin Dolske
wrote on
:
Mook
wrote on
:
Arivald
wrote on
:
Wladimir Palant
wrote on
:
tito
wrote on
:
Jorge
wrote on
:
Kohei Yoshino
wrote on
:
Skuallpa
wrote on
:
joliclic
wrote on
:
Jorge Villalobos
wrote on
:
Vikas Agarwal
wrote on
:
Jorge Villalobos
wrote on
:
James Newell
wrote on
:
Max
wrote on
:
V
wrote on
:
Jorge Villalobos
wrote on
:
V
wrote on
: