top | item 5437789

Compiling LLJS to asm.js

101 points| jlongster | 13 years ago |jlongster.com | reply

34 comments

order
[+] STRML|13 years ago|reply
LLJS, asm.js, & Emscripten are really moving Javascript forward at incredible speed. I wonder if these projects will affect the future of the JS spec (ECMAScript Harmony + above). It's an exciting time to be a web programmer.
[+] abecedarius|13 years ago|reply
Yesterday I rewrote a tiny Javascript demo in asm.js and also saw an order-of-magnitude speedup. (I thought at first it didn't help at all, apparently because the framerate was limited by setInterval().)

Code at http://wry.me/hacking/canvas_asm.html

[+] srijs|13 years ago|reply
Cool. I recently wrote a low-level sha1 implementation in pure javascript, trying to leverage asm.js (http://github.com/srijs/rusha).

Can you tell me, how did you confirm you wrote valid asm.js and there was no fallback-mechanism kicking in?

I benchmarked my implementation, of course, and noticed a 2x speedup. However, this seems quite less for the this type of low-level algorithm...

[+] simcop2387|13 years ago|reply
Doesn't appear to be doing anything for me,

    noasm 285
    asm 13
    asm 13
    noasm 269 
That's all that appears in the console. Network and everything looks fine, no 404 or other errors.
[+] gruseom|13 years ago|reply
That is the most exciting news I've heard in quite a while.
[+] kayoone|13 years ago|reply
Whats the use for LLJS ? I dont really get it. So its not meant to be used in web development but for things like games or complete VMs. But isnt it much simpler for those cases to compile existing C codebases with emscripten instead of rewriting everything in LLJS ? Even if you start today with writing a new game engine, wouldnt it make more sense to use C++ and be able to target any platform there is instead of just the browser?
[+] jlongster|13 years ago|reply
The main use for something like LLJS is to allow you to target asm.js with new code that you write. It's true that it's probably not the best idea to completely rewrite a 3d engine in it (right now), but it gives you a quick way to rewrite core parts of an intensive app (like a 3d game) for high performance. There are "inner loops" that could benefit from a small amount of LLJS.

As the post says, it's a proof of concept and a way to open up asm.js to people who want to tinker with it without compiling C code with emscripten.

[+] azakai|13 years ago|reply
For a big codebase, yes, compiling C/C++ using emscripten or such is a good idea. But if you want to write a tiny part of a normal JS application in something faster, lljs is convenient. Sort of like you would write inline assembly in C perhaps.
[+] niggler|13 years ago|reply
Has anyone built the entire stack in javascript (C to JS compiler in JS + standard library) so that you could write JS applications in C and compile and run in the browser?

EDIT: to clarify, the ideal solution would be an editor (like codemirror or ace) with a compile+run button that would compile the code down to JS and run it.

[+] y0ghur7_xxx|13 years ago|reply
I am sure there is some reason this can't be done, but can we compile JavaScript to asm.js? If this can be done with C, it can be done with JS?
[+] jlongster|13 years ago|reply
Sure, but it's different because you need to compile a whole VM to asm.js and run javascript inside of it. You can't compile a dynamic language like javascript to low-level code because you need too much information at runtime.

See this project, which compiles SpiderMonkey to javascript via emscripten, which supports asm.js: https://github.com/jterrace/js.js/

[+] gruseom|13 years ago|reply
How far are we from being able to do meaningful text processing with typed arrays and (therefore, presumably) asm.js? Last I checked, there was work being done on a string encoding/decoding standard but it wasn't implemented in browsers yet. Can anyone say more about this?