Why Javascript engines are so slow?
Moderators: hgm, Rebel, chrisw
-
- Posts: 708
- Joined: Mon Jan 16, 2012 6:34 am
Why Javascript engines are so slow?
On chess.com and lichess.com, the javascript stockfish analysis is extremely slower than normal UCI interface. In my computer, with UCI, I get around 10Mns (depth around 25-27 instantly) but with javascript I get only about 5Mns (depth around 20). While we can easily use playstation emulator or android emulator in Window program, why not between those two languages/instructions.
-
- Posts: 27808
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Why Javascript engines are so slow?
That is extremely fast, for JavaScript, isn't it? JavaScript is an intrinsically slow language, because the variables are untyped, and ca hold objects of any size. So that at run time you would have to keep track of what is in the variable, and how big it is. It must have a pretty smart compiler to be only twice slower as C.
Anything better than 5% of the speed of the equivalent C program should be considered a small miracle.
Anything better than 5% of the speed of the equivalent C program should be considered a small miracle.
-
- Posts: 2559
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: Why Javascript engines are so slow?
Only 2x slower compared to native C++? They probably used emscripten, webassembly should do even better in the near future.Nay Lin Tun wrote:On chess.com and lichess.com, the javascript stockfish analysis is extremely slower than normal UCI interface. In my computer, with UCI, I get around 10Mns (depth around 25-27 instantly) but with javascript I get only about 5Mns (depth around 20). While we can easily use playstation emulator or android emulator in Window program, why not between those two languages/instructions.
Do you understand that Javascript is a dynamic language and those are extremely difficult to JIT?
That's also why modern Javascript VMs are extremely complex.
Many years ago javascript was interpreted, imagine how that would run.
-
- Posts: 389
- Joined: Wed Sep 26, 2012 1:29 pm
- Location: Hungary
Re: Why Javascript engines are so slow?
As Niklas Fiekas said they use WebAssembly:mar wrote:Only 2x slower compared to native C++? They probably used emscripten, webassembly should do even better in the near future.Nay Lin Tun wrote:On chess.com and lichess.com, the javascript stockfish analysis is extremely slower than normal UCI interface. In my computer, with UCI, I get around 10Mns (depth around 25-27 instantly) but with javascript I get only about 5Mns (depth around 20). While we can easily use playstation emulator or android emulator in Window program, why not between those two languages/instructions.
Do you understand that Javascript is a dynamic language and those are extremely difficult to JIT?
That's also why modern Javascript VMs are extremely complex.
Many years ago javascript was interpreted, imagine how that would run.
http://talkchess.com/forum/viewtopic.php?t=63404
-
- Posts: 389
- Joined: Wed Sep 26, 2012 1:29 pm
- Location: Hungary
Re: Why Javascript engines are so slow?
Do you see this slowness with WASM on on lichess.org?Nay Lin Tun wrote:On chess.com and lichess.com, the javascript stockfish analysis is extremely slower than normal UCI interface. In my computer, with UCI, I get around 10Mns (depth around 25-27 instantly) but with javascript I get only about 5Mns (depth around 20). While we can easily use playstation emulator or android emulator in Window program, why not between those two languages/instructions.
https://en.lichess.org/blog/WPSD5icAAKM ... on-lichess
-
- Posts: 2821
- Joined: Fri Sep 25, 2015 9:38 pm
- Location: Sortland, Norway
-
- Posts: 4607
- Joined: Wed Oct 01, 2008 6:33 am
- Location: Regensburg, Germany
- Full name: Guenther Simon
Re: Why Javascript engines are so slow?
Is this a random 'computerchess bot' post?Nordlandia wrote:Static evaluation can be found on this site ->
https://hxim.github.io/Stockfish-Evaluation-Guide/
It has absolutely nothing to do with this thread...
https://rwbc-chess.de
trollwatch:
Talkchess nowadays is a joke - it is full of trolls/idiots/people stuck in the pleistocene > 80% of the posts fall into this category...
trollwatch:
Talkchess nowadays is a joke - it is full of trolls/idiots/people stuck in the pleistocene > 80% of the posts fall into this category...
-
- Posts: 338
- Joined: Tue Mar 13, 2012 9:59 pm
- Location: Germany
Re: Why Javascript engines are so slow?
The lichess.org local chess engine is no javascript. It's PNACL for Chrome and WASM for Firefox >=v52.0
It allows to run code written in several languages (C++ for Stockfish) in your browser at near native speed.
But as you experienced, it's still not 100% as fast as your native engine in your favorite GUI. But still - much faster than Javascript
It allows to run code written in several languages (C++ for Stockfish) in your browser at near native speed.
But as you experienced, it's still not 100% as fast as your native engine in your favorite GUI. But still - much faster than Javascript
-
- Posts: 1296
- Joined: Sun Mar 12, 2006 6:46 pm
- Location: Kelowna
- Full name: Tony Mokonen
Re: Why Javascript engines are so slow?
It was obviously meant to be posted in a different thread. People do click the wrong button sometimes. I am not sure why you would be so upset about it.Guenther wrote:Is this a random 'computerchess bot' post?Nordlandia wrote:Static evaluation can be found on this site ->
https://hxim.github.io/Stockfish-Evaluation-Guide/
It has absolutely nothing to do with this thread...