JavaScript performance

General project discussion.
Use this as a last resort if your topic does not fit in any of the other boards but it still on-topic.
Forum rules
This General Discussion board is meant for topics that are still relevant to Pale Moon, web browsers, browser tech, UXP applications, and related, but don't have a more fitting board available.

Please stick to the relevance of this forum here, which focuses on everything around the Pale Moon project and its user community. "Random" subjects don't belong here, and should be posted in the Off-Topic board.
GAPOaltPOCA
Banned user
Banned user
Posts: 10
Joined: 2021-06-14, 06:26

JavaScript performance

Unread post by GAPOaltPOCA » 2021-06-18, 17:29

It's a normal script to calculate a series by recursion. The only thing different is I changed the iterator from 1 to 10000 to 1 to 1000000000.

Chrome completed the script in about 9s. Basilisk meanwhile ran about a minute then display a message asked me to stop the script. The browser is unresponsive while the script being run, so I choose to stop the script. Everything back to normal.

I don't have FF to test if it survive or not. But from this experience, I know for sure why sometimes the browser just hangs on JavaScript heavy site. Not only because these sites use too new JavaScript features the browser not yet supported, but also because the JavaScript engine is too slow.

I downloaded both Microsoft ChakraCore (seems abandoned since they switch to V8) and Mozilla JSShell. Both of them completed the script about 12s and 11s respectively. I surprised that ChakraCore is actually slower than Mozilla!

I wonder if the JavaScript engine we use is the same as FF? They seems to be the same name, SpiderMonkey. But I think we are different, don't we? Because our SpiderMonkey doesn't need Rust. Mozilla SpiderMonkey seems to need Rust. Ours could be an old version of SpiderMonkey, before Rust, I think.

Please correct me if I'm wrong.

p/s: V8 is just incredible. I wonder how much money actually pulled into it. Meanwhile, Mozilla Rhino can't even complete the script. It ran for 15 minutes without any signs it will be able to complete it at all, so I have to cancel it. Bellard's QuickJS took more than 5 minutes to complete the script.

vannilla
Board Warrior
Board Warrior
Posts: 1718
Joined: 2018-05-05, 13:29

Re: JavaScript performance

Unread post by vannilla » 2021-06-18, 19:41

Synthetic benchmarks can't really provide accurate measures related to actual usage of the program, especially so when the benchmark only calculates recursion.

Also, you should be amazed that Chrome didn't display any prompt to stop the running script. What if it was a script with an infinite loop?
Basilisk correctly asked you what to do in the case of poorly written code.
Actually, not long ago I happened to find out what happens when you write an infinite loop and run it in Chrome: the page is obviously unresponsive but most interestingly the UI is absolutely slow. I was never asked if I wanted to stop the script and all I could do was clicking the button to close the tab, waiting forever until the browser managed to process it.
If it was Basilisk or any other UXP-based browser I would've been presented with that prompt pretty much immediately (after the set interval, of course.)

GAPOaltPOCA
Banned user
Banned user
Posts: 10
Joined: 2021-06-14, 06:26

Re: JavaScript performance

Unread post by GAPOaltPOCA » 2021-06-25, 15:47

Is there anyway to bypass this prompt and keep the script running? Of course I know I could refuse to stop the script when being asked but the dialog will keep popup again and again. And on Chrome, you have the Task Manager. I think you could force ending of not responding scripts using it. Or Chrome just automatically stop the offending scripts without notice me? Because I have never had any problems browsing using Chrome, even on sites with offending scripts that will be problematic on Pale Moon (or maybe Firefox, too. I recall I did see similar dialog on Firefox but I'm unsure if it still applies on newer versions of Firefox).

BenFenner
Lunatic
Lunatic
Posts: 297
Joined: 2015-06-01, 12:52
Location: US Southeast

Re: JavaScript performance

Unread post by BenFenner » 2021-06-26, 19:11

GAPOaltPOCA wrote:
2021-06-25, 15:47
Is there anyway to bypass this prompt and keep the script running? Of course I know I could refuse to stop the script when being asked but the dialog will keep popup again and again.
I think after you dismiss the prompt a few times it displays a new check box. From memory that check box allows you to finalize the choice.

GAPOaltPOCA
Banned user
Banned user
Posts: 10
Joined: 2021-06-14, 06:26

Re: JavaScript performance

Unread post by GAPOaltPOCA » 2021-07-02, 09:21

BenFenner wrote:
2021-06-26, 19:11
GAPOaltPOCA wrote:
2021-06-25, 15:47
Is there anyway to bypass this prompt and keep the script running? Of course I know I could refuse to stop the script when being asked but the dialog will keep popup again and again.
I think after you dismiss the prompt a few times it displays a new check box. From memory that check box allows you to finalize the choice.
No. It will keep display the prompt again and again. FF has the same behavior, too. I just tested and I can't let the script complete, FF just keeps asking to stop the slowing down script. Meanwhile Chrome happily runs the script and return the result almost instantly. I found it's weirded since with Mozilla JSShell it completed the script so fast but with FF itself it can't complete the script. The same script engine being used, isn't it? Why the browser is too much slower than the standalone JSShell? It seems there is some built in time out mechanic that blocked the execution of a script it thinks will slow down the browser and there is no way to bypass it.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 30574
Joined: 2011-08-28, 17:27
Location: Tranås, SE
Contact:

Re: JavaScript performance

Unread post by Moonchild » 2021-07-02, 20:59

JSShell isn't a full browser. It's for bare JS only. Any interaction with the DOM, for example, doesn't exist.
It's rather telling though if even Firefox who is Google's sanctioned opposition that is in behaviour copying Blink wherever it can, is running into issues. The scripting is likely just wrong.
"Son, in life you do not fight battles because you expect to win, you fight them merely because they need to be fought." -- Snagglepuss
Image

Post Reply