Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is JavaScript slower in a FireFox add-on than in a webpage loaded in FireFox?

I wonder why the same JavaScript code is considerably slower in a FireFox add-on (using the Add-on SDK) than directly running in a web page loaded in FireFox.

For instance, this code:

function isPrime(number) {
    var i,
        prime = true;
    for(i = 2 ; i < number ; ++i) {
        if(number % i === 0) {
            prime = false;
        }
    }
    return prime;
}

function sumFirstPrimeNumbers(x) {
    var i,
        sum = 0;
    for(i = 1 ; i <= x ; ++i) {
        if(isPrime(i)) {
            sum += i;
        }
    }
    return sum;
}

var sum = sumFirstPrimeNumbers(15000);

console.log(sum);

takes less than 2 seconds to run in a webpage opened in FireFox, but takes about 15 seconds to run in a FireFox add-on.

I know the code could be better, but it is only an example to show how slow it is.

Why is it that slow in a FireFox add-on?

Is there any way to get it faster (without changing this code since it is, as I said above, only an example)?

Update:

It seems to be related to the Add-on SDK. I did another test: I executed the same code in an add-on which does not use the add-on SDK and the code execute in about 3 seconds.

Why such a huge difference (3 seconds vs 15 seconds) between an add-on using the add-on SDK and an add-on not using it?

like image 239
antoyo Avatar asked Jun 16 '13 18:06

antoyo


People also ask

Why does Firefox keep slowing down?

Block unneeded content. Content you don't need such as ads or tracking scripts can significantly slow down page loading. Firefox's built-in content-blocking feature can make the pages load faster by preventing third-party trackers from loading.

Why is Firefox so slow compared to Chrome?

I found that Firefox used more RAM than Chrome, which not only debunks Mozilla's claims but comes as a huge surprise considering Chrome's reputation as a computer performance killer. With this in mind, Firefox is likely to slow down your computer faster than Chrome is.

Why does it take so long for Firefox to load?

Mozilla Firefox may take a long time to load due to an old cache or cookies stored on your computer, as they may take a substantial amount of time to retrieve information. Startup time also depends on your home page and tab preferences.


1 Answers

There are two preferences (accessible from the about:config page) that control the javascript optimizations: javascript.options.methodjit.chrome for privileged code (extensions) and javascript.options.methodjit.content for untrusted code (web pages).

Some versions of Firefox ship with the former disabled by default.

Check javascript.options.methodjit.chrome to see if it's set to true.

like image 142
paa Avatar answered Nov 02 '22 17:11

paa