Hacker News new | ask | show | jobs
by borisyankov 3386 days ago
For anyone wondering: 'Why JavaScript? Why React?', let me remind you, the goal of ReactVR is not to create the most performant game, but to allow the people that are creating websites right now, to create VR websites in future.

Using the same technologies is natural.

2 comments

I would add that there is absolutely no technical reason why an application expressed in one language need not be as fast as an application expressed in another. First, compilers improve static analysis, and second, JIT analysis will also improve. For this sort of thing, running on the GPU matters a lot more than source language, and WebGL has you covered there.
This is wrong. There absolutely are technical reasons why implementations of different languages perform differently- no amount of static or runtime analysis can entirely save you from performance-hostile semantics baked into the language spec.

WebGL is a huge bonus, but WebAssembly will also be important for a lot of web-based VR.

> no amount of static or runtime analysis can entirely save you from performance-hostile semantics baked into the language spec

You can in almost all cases check for these semantics statically, and if not found, run a super fast path. This is the whole premise behind asm.js.

Heck, even C++ has plenty of features that have performance-hostile semantics. But the compiler checks for these and you don't pay the penalty if you don't use them.

Wasm will help, but I disagree that anything in the JS spec makes the _language itself_ inherently slower than any other language, if we disregard textual compilation overhead.

I'll give you one: value types.

Until you can specify memory layout you'll never come near a proper gamedev engine, regardless of GC issues(which are also a problem).

(source: I used to work on professional game engines)

You're right, which is why one of the fundamental optimizations in a modern Javascript engine is inferring static memory layouts for your objects. Another is getting rid of unnecessary allocations to reduce the need for GC.
> inferring static memory layouts for your objects

I'm deeply suspicious that you'll do better than something purpose built. Things like arena allocators for levels. Knowing how your scene-graph and animation traversal are really hard to get right and without direct control over SoA vs AoS and the like I don't see how you get within a factor of 10 to something written in native.

asm.js and WebAssembly give you the same control over memory layout as C (in fact the memory layout is absolutely identical to a little-endian 32-bit host) and unless you need to call a lot out into HTML5 APIs the garbage collector will be idle. These two things together are basically the magic sauce why asm.js/wasm are faster than manually written JS and faster then most 'managed languages' where most objects are created on the heap and passed around by reference.
Totally, since the memory model is identical. However then you're not really talking about something that looks like JS(or a managed language) at all.

I'm actually a huge fan of WASM, I think it gives you a great escape hatch to break out of these problems(much like JNI/etc in other managed languages).

> asm.js and WebAssembly give you the same control over memory layout as C

That's a bold statement right there.

Luckily most JS engines "unbox" simple values to "value types" if it can be determined that they will stay that way.

so aside from startup speed you get the same perf

> simple values

So does every other language, where it matters is with objects. Until I can mark a whole object as a value type and fix it in memory relative to other objects then you'll pay a 10-50x slowdown for cache misses and the like.

> asm.js

But then you're no longer using the language. The performance-hostile semantics are still there, you're just not using that part of the language, and thus losing out on all their benefits.

Yeah the whole reason asm.js is fast is because it strips out the performance hostile parts of js.
The ReactVR framework can use asm.js to gain acceleration but you as a front-end developer could stick to best JS VR practices to not get in the way of the performance ReactVR with asm.js brings you (if it uses it now or in the future).
Any language that uses LLVM isn't using the language either, by this definition. That would be a shock to most C++, CUDA and Swift developers.
How so? LLVM is used to implement language features, performance-hostile ones included. asm.js is a codified way to avoid language features.

You may be confusing layers here. asm.js as a compilation target is used the same way as LLVM- it is used to implement the source language's features, while simultaneously avoiding some of JS's.

> I would add that there is absolutely no technical reason why an application expressed in one language need not be as fast as an application expressed in another.

There absolutely is.

If I write a program in a language that's fuzzy enough that a machine (which follows the specifications of the language) cannot definitely tell what I was asking it to do at compile time, there are compiled optimizations it can never rely on.

You make a good chunk of that back with JIT / predictive runtime compiling, but it's never going to be the same. At minimum, you're burning CPU and cache on your miss rate. To say nothing of the additional overhead of running JIT while executing in the first place.

As I understand it, this is the entire purpose of things like Vulkan / Webasm. (I realize they're primitive targets vs high level language, but same principle applies at any level of the stack)

Happy to have someone tell me I'm wrong, but the original quote flies in the face of everything I learned in language / compiler design.

This is a good comment. Ideally, JIT would reach some asymptotic improvement and then stop running. It would only need to start running again if the code changes.

I think however there is some fundamental communication issues talking about "compilers vs language". Optimizing compilers, by definition, rewrite your code into a "better" form. Even if you are writing C/C++ you probably don't really know what's happening at the register level. Heck, with todays CPUs I wonder if even assembly people know what's actually happening in the registers!

And in x86 at least, even the assembly gets sliced and diced behind the scenes.

There have been comments to the same effect on HN before, but I look at language design as an API between humans and computers. Computers need as strict rules on how to execute a thing as possible: humans need something comprehensible. The ideal language finds ways you can increase the former without decreasing the latter (in ways they notice).

Theoretically that may be true, but in reality there are a lot of little detail problems which cannot simply be hand-waved away. For instance, WebGL behaves very differently compared to a native 3D API, mainly because there's a much longer pipeline for each call from JS to the driver. Manually written JS has garbage collection spikes, input and audio have much higher latency. I think WebVR provides shortcuts for some of those problems, and mobile/web VR content needs to be designed with those limitations in mind, I just want to point out that the browser platform is full of technical limitations and compromises compared to 'bare metal' platforms which at most can be softened a bit, but will never completely disappear, no matter how much code is thrown at the problems.
In the real world case though there are lots of extant technical reasons why this won't be as performant. As the parent says though it's okay for its usecase.
In the meanwhile many people like me who love TS/Flow wait for the days when their annotations could be used to optimize their apps. If types on JS doesn't come I'm sure someone will compile TS to WebAssembly or something.

I'd be in even just for the possibility for reflection/dependency injection.

Javascript I get, but React? Why use a flavor-du-jour library for something like this?
People have been using React since 2014. Is 3 years really still "du jour"?
Yes absolutely. Unfortunately in the javascript world it probably means that it's legacy by now.
Certainly, compared to something solid and well-understood like Javascript which has been around since 1997.

I'd complain the same way if it were a C++ project requiring Boost or something.

Boost has existed since 1999-2000, which aligns with ES3.

As for solid and well-understood... Douglas Crockford wrote a book on how "solid" Javascript is, called "Javascript: The Good Parts". One of his most common refrains about JS was "Javascript is The World's Most Misunderstood Programming Language". [0][1]

ES5 came out in 2009. ES6 was standardized after React came out.

[0] - http://javascript.crockford.com/javascript.html

[1] - http://javascript.crockford.com/popular.html

Yes, yes it is
It's about having a declarative UI library. React is just the syntax Facebook prefers.
Shall we do it in jQuery?