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

I wonder why the same JavaScript code is much slower in addition to FireFox (using the Add-on SDK) than it directly works on a web page loaded in FireFox.

For example, 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); 

it takes less than 2 seconds to launch on a webpage opened in FireFox, but takes about 15 seconds to launch in addition to FireFox.

I know that the code may be better, but this is just an example showing how slow it is.

Why is it slower in addition to FireFox?

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

Update:

It looks like this is due to the additional SDK. I did another test: I executed the same code in an add-in that does not use the add-in SDK, and the code runs in about 3 seconds.

Why is there such a huge difference (3 seconds versus 15 seconds) between an add-in using an additional SDK and an add-in not using it?

+6
source share
2 answers

There are two parameters (available from the about:config page) that control javascript optimization: javascript.options.methodjit.chrome for privileged code (extension) and javascript.options.methodjit.content for untrusted code (web page).

Some versions of Firefox come with previously disabled by default.

Check javascript.options.methodjit.chrome to determine if true .

+1
source

There is also a bug in current versions of firefox that prevent full JIT javascript in add-ons, see https://bugzilla.mozilla.org/show_bug.cgi?id=913182 for details

+1
source

Source: https://habr.com/ru/post/947414/


All Articles