11

I recently started doing some investigations into ASM and I've played with a few of the demos online. I must say that the Unreal demo was quite impressive... I've been developing an app using Three for a large number of months now. It works beautifully on fast machines, but on lower end ones it tends to struggle. When I ran the unreal demo on my lower end machines, the demo worked like a dream. My question is, what place might ASM have with Three - could it vastly speed up the engine? Is it worth while investigating or developing a solution that utilises both and switching between them based on the browser? Also would there be any plans for Three to take advantage of it in the future?

I came from a C++ background, and would be quite interested in the prospect of developing something. But at the same time it would mean having to re-learn the language and even more problematic might be the large amount of time it would take to get it to a usable point.

What are your thoughts?

2 Answers 2

14

This is my opinion:

First and foremost, asm.js isn't really meant to be written by hand. Altough I say that It certainly is possible to write it as it has a validator. The unreal demo is something that has been compiled into asm.js with emscripten. It also doesn't need to interact with other code outside the code that gets compiled. So it generates highly optimized code because of the fact that the unreal demo is already highly optimized code in C++, It gets optimized by a compiler and then gets another run of optimisations through asm.js.

Secondly, asm.js is actually only supported by firefox. Altough all other browsers can execute it but on most it still incurs a performance penalty. This penalty is if you compare asm.js code that does the same as normal javascript code. Just search jsperf.com for examples of this.

Okay, This is some general guide lines about asm.js. Now let's talk about Three.js.

Firstly, because THREE.js has to interact with usercode, it isn't easy to write an asm.js library because of it's many restrictions (no objects).

Secondly, Three.js will not gain much performance a whole lot in performance for calculations where asm.js is strong in. But will gain more from future updates from the browsers. (for instance, the creation of typedarrays in chrome which is now a pain point in THREE.js is comming soon. V8 issue)

Thirdly, The code in asm.js needs to manage its own memory. Which would mean that THREE.js has to figure out a way to make a large apps work with limited memory. Or make every application very memory hungry.

Fourth, comparing the unreal demo with three.js is a bit unfair due to the fact that three.js tries to allow everyone to write 3D apps while the unreal engine is a highly optimized engine for 3D games.

As you've noticed, I'm mostly against asm.js in three.js. But that's becuase it's too early to tell what the best way to go is. There is a high probability that asm.js will get a place in three.js eventually but for more a limited use as renderer-only for instance. But for now, there are still too many unsolved questions around asm.js.

But If you want to use asm.js and use C++, Then i recommend emscripten which was used to build the unreal demo.

This is of course my opinion. But I think it somewhat represents what @Mr.doob and @WestLangley had in mind. And sorry about the long post.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Gero3, that's exactly what I was looking for. You've actually confirmed a lot of what I thought and hoped. I was a bit confused about chrome. When I tested in v22 the unreal demo broke the whole browser but in canary it worked. I googled to see if had been included and heard a mention of it - so I assumed it was added. But Having looked again I can see it does not have the support. I also completely take your point on Unreal v Three. Three is indeed a great library and I just wanted to see what others thoughts were on ASM and three using the Unreal demo as my talking point.Thanks again!
1

The best way to find out is to write a small demo in C (by hand) then compile to asm.js and run it, then write the same small demo in JS with Three.js (by hand) then run that, and compare the differences in both developer experience as well as performance.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.