Live data from Hacker News

We've been lied to: JavaScript is fast

jyelewis.com

21–30 of 86 posts

Re: We've been lied to: JavaScript is fast

#22
Some anecdata: Node was roughly as fast as dmd, the D compiler for fast iteration. The LLVM and GCC based D compilers are hugely faster.

By using JavaScript you are throwing away something like 2-3x.

There will be cases where JS can keep up because it reduces to a local loop which gets optimized the same way as any other language, but all those little other bits add up.

Same with Python. If you do everything in numpy you can be very fast, but what happens if you don't? You could use a fancy jit but now you have a deeper stack with no control over the emitted code - nice if you already have the code, but not ideal.

Re: We've been lied to: JavaScript is fast

#23
Those are some really bad benchmarks.

JavaScript is probably like 10x or 100x slower than C or similar languages when you write something bigger and any of the following happens:

- the ratio of code size to run time is too big. Then the jit can’t keep up.

- you use a lot of value types. Them be structs in C, no need for allocation. In JS them be objects. The JS VM will try to escape analyze them, and it will succeed some of the time, but fail enough of the time to cause massive punishment.

- you churn objects while having a large base heap size and the generational hypothesis holds only a bit. Then you’ll wait for the GC a lot.

- you have a class hierarchy with many descendants and you often access properties or call methods on the base type. Then vtables or whatever work great but JS inline caches blow up.

- probably lots of other conditions.

Write enough code and at least one of these will hold and you’ll be slow in JS, fast in C.

(Source: I work on JSC and I implemented a lot of its optimizations. Benchmarks like the ones in this post are the sort of thing my JITs eat for breakfast. It’s cool to see people throwing me softballs but I like to be honest about what the technology I work on is capable of.)

Re: We've been lied to: JavaScript is fast

#24
post #19

Stop writing C code like this author does! C is a language for experts and there are lots of things that are wrong here. Especially when writing benchmark code, when you do want the compiler to optimize. > int main() The easiest way to find someone who's inexperienced in C is to find someone who declares a function that takes no arguments with an empty pair of parentheses. In C but not C++ you need to write "void" in…

Adding unreachable to random places you think the compiler should already know about can yield some perf wins!

Compilers are quite chaotic when you get deep in the passes.

Re: We've been lied to: JavaScript is fast

#25

JavaScript is still really slow compared to compiled languages - C, C++, even Java. That super-simple benchmark even after JIT is still 2-3x as slow as the C version, and more complex code can’t be optimized nearly as well. I can confidently say that games and apps in the browser and Electron are noticeably slower than other apps. You don’t see many web games because the graphics required for games today can’t really…

Electron apps are memory heavy and slow at interaction because Chromium loads a ton of rendering and Web API code into memory, and interactions triggered by keyboard/mouse/touch input go through layers of non native handlers so that event listeners behave uniformly across devices. It's all part of a complex rendering loop, and whether an element has a fixed position during scroll can affect memory and performance by hundreds of times compared to those 2x js-vs-native you mention.

Oh, and the Web API has has stuff you wouldn't expect like USB, Bluetooth, MIDI, vibration, TPM etc.

Re: We've been lied to: JavaScript is fast

#26

I hope someday we can convert python to javascript, or even embed python into web pages. There are too many languages these days, for me at least.

To answer my own question there are 2 active python to js efforts:

    https://brython.info/static_tutorial/en/index.html
    https://github.com/qquick/Transcrypt

Re: We've been lied to: JavaScript is fast

#27

JavaScript is still really slow compared to compiled languages - C, C++, even Java. That super-simple benchmark even after JIT is still 2-3x as slow as the C version, and more complex code can’t be optimized nearly as well. I can confidently say that games and apps in the browser and Electron are noticeably slower than other apps. You don’t see many web games because the graphics required for games today can’t really…

> I can confidently say that games and apps in the browser and Electron are noticeably slower than other apps

In my experience the great majority of perceptible slowness in browser apps comes from DOM reflows, not JavaScript

Re: We've been lied to: JavaScript is fast

#28
post #3

Yes but. https://dev.to/jaredcwhite/the-shocking-immaturity-of-javasc...

I don't know that I agree with this article, while there is absolutely a problem with package/framework/build tools churn that makes development super painful, I don't feel that developing with JavaScript has been any more painful than developing with VB, C#, PHP etc was in the past. All languages have their pain points, and modern JS/TS, while undisputably having their quirks, aren't particularly more quirky than JS…

I recently got back to a web app with node I'd been working on two years ago, and I'm finding packages deprecated, command-line arguments that no longer work, etc. Lots of breaking changes all the time. There's definitely something worse than average with the node development experience. Things are quickly changing and at the same time very poorly documented.

Re: We've been lied to: JavaScript is fast

#29
post #19

Stop writing C code like this author does! C is a language for experts and there are lots of things that are wrong here. Especially when writing benchmark code, when you do want the compiler to optimize. > int main() The easiest way to find someone who's inexperienced in C is to find someone who declares a function that takes no arguments with an empty pair of parentheses. In C but not C++ you need to write "void" in…

All the C compilers I know of can handle "int main()" just fine. Is there any practical reason to prefer "int main(void)"?

Re: We've been lied to: JavaScript is fast

#30

Earlier quoted context omitted.

I don't know that I agree with this article, while there is absolutely a problem with package/framework/build tools churn that makes development super painful, I don't feel that developing with JavaScript has been any more painful than developing with VB, C#, PHP etc was in the past. All languages have their pain points, and modern JS/TS, while undisputably having their quirks, aren't particularly more quirky than JS…

I recently got back to a web app with node I'd been working on two years ago, and I'm finding packages deprecated, command-line arguments that no longer work, etc. Lots of breaking changes all the time. There's definitely something worse than average with the node development experience. Things are quickly changing and at the same time very poorly documented.

Well, why did you choose packages that change quickly and are poorly documented then? There are packages that, OTOH, have up to zero dependencies, and haven't changed in years; if you consider those stale, I guess nobody can help you.
Post reply on HN