News for hackers. Stuff that matters.
Re:Why the New V8 Is So Damn Fast by josephg on Monday July 30, 2018 @08:23PM (#17649508)
> javascript actually makes sense and can be the most performant.

Thanks to V8 you can definitely achieve good enough performance with JavaScript for most applications, and the ergonomics are pretty great. But it’s not true that performance rivals or beats C in the general case. The ‘sufficiently advanced compiler’ rainbow is something that Java has spent decades chasing. I think it’s fair to say at this point that humans are better at writing C code than we are at writing clever compilers.

It’s many of the exact ergonomics which make JavaScript useful and easy to use that also make it much harder to optimise. For example, what code should V8 generate for `x+=x` ? The optimiser might find that x is always a positive integer, but every time it gets doubled, it might cross the magic overflow point where it needs it’s representation swapped for a double. The generated code must check for this every time. Or consider memory management - For games I’ve heard of people making a per-frame arena allocation pools for values with a lifetime that won’t cross frame boundaries. This basically makes these allocations free and improves cache coherency. I’m happy that the JS GC is multithreaded now, but there’s no way a GC can compete with that. And unlike C, there’s no way in JS to override the allocation behaviour.

There are a million paper cuts like this which lower the ceiling of how fast optimised JS can run. I’m glad V8 will keep improving, but for my money the future of really fast JavaScript is Webassembly.

Re:Why the New V8 Is So Damn Fast by ux-app on Monday July 30, 2018 @09:28PM (#17649836)
>For games I’ve heard of people making a per-frame arena allocation pools

Games are a special case where each ms counts. Globally, the number of LOC written for consumer or business software dwarfs that of game code and for these kinds of applications JS is well within the realm of performant enough. That assumes you're not doing your presentation layer using the DOM though which is still garbage wrt performance. Luckily there are things like Qt to make high performance UIs in though.

Re:Why the New V8 Is So Damn Fast by josephg on Monday July 30, 2018 @10:57PM (#17650205)
Yes I think we all agree. As I said in my post above:

>> Thanks to V8 you can definitely achieve good enough performance with JavaScript for most applications

The point I argued above isn’t that JS is slow. It’s that JS will probably always be slower than well written C code. I still write far more JS than C, because my time is usually more valuable than the computer’s.

That said, games are far from the only place where every ms counts. Performance matters in database servers, operating systems, real-time applications (eg robotics), text editor typing latency, UI responsiveness, 3d modelling software, video encoding, cryptocurrency mining, browser DOM rendering and so on.

I love JS, but native code is not a special case. Despite the best efforts of Electron, I suspect most of the globe’s aggregate clock cycles are spent running code written in languages other than JavaScript.

Re:Why the New V8 Is So Damn Fast by pjmlp on Tuesday July 31, 2018 @02:20AM (#17650960)
Thankfully the world of managed languages is not constrained to JavaScript, nor C is the only option for unmanaged ones, a language that we would consider no respectful games programmer would use, after all a good game engine should be written in Assembly.

Ironically it is now used as the language to beat.

Re:Why the New V8 Is So Damn Fast by weberc2 on Monday July 30, 2018 @10:56PM (#17650201)
I don’t use JS regularly because the ergonomics of async have been so poor. This might not be the case with recent async/await work, but I’ve also not had positive async/await experiences in other languages either. This is too bad because V8 seems like a dream compared to CPython or even Pypy, but I prefer Go to both, especially when it comes to I/O.
Re:Why the New V8 Is So Damn Fast by azhenley on Monday July 30, 2018 @09:22PM (#17649807)
You make some interesting points about cases where JS will always be difficult to be optimized automatically.

I wonder if compiler hints can help in that regard? For example, if performance is important then you could annotate the 'x+=x' line to tell the compiler to not check for overflow.

Re:Why the New V8 Is So Damn Fast by imtringued on Tuesday July 31, 2018 @07:04AM (#17652136)
We have that already. It's called asm.js and it's successor is WebAssembly.
Re:Why the New V8 Is So Damn Fast by amelius on Tuesday July 31, 2018 @05:32AM (#17651737)
Another option would be that the compiler deduces when exactly the statement x+=x would need to switch from integer to double. That's more difficult, and impossible in general, but not impossible in specific cases.
Re:Why the New V8 Is So Damn Fast by Thiez on Tuesday July 31, 2018 @02:30AM (#17650998)
Sure, you can hint with OR: `x = x | 0; x = (x + x) | 0;`. Bitwise operators always work on 32 bit integers in js. I'm not sure whether the js vms actually need or use this information.