Not a bug! asm.js is *fast*...

147 views
Skip to first unread message

Mark Sibly

unread,
Jul 27, 2015, 3:53:31 PM7/27/15
to emscripten-discuss
Hi,

I am working on a 'transpiler' style language that outputs c++, which I then either compile as native code to produce desktop apps, or put through emscripten to produce web apps.

I've recently been working on the garbage collection stuff, and decided to run a few speed tests as I have long been worried ask.js wouldn't be up to this sort of thing.

But much to my surprise, in many cases, the asm.js code runs *faster* than the native code! I can tweak some GC settings so this isn't the case, but with default settings asm.js is about 20% faster than the corresponding native code.

The test code is meaningless 'thrash the GC' sort of stuff so I'm not taking the results too seriously yet, but I'm still a bit confused - how can this be? What sort of voodoo is asm.js up to here?

Also: does asm.js produce garbage if it's just running 'raw' code, ie: no API calls?

Bye!
Mark





Mark Sibly

unread,
Jul 27, 2015, 6:28:18 PM7/27/15
to emscripten-discuss, blitz...@gmail.com
Ok, it appears em++ may be optimizing out some stuff that g++ isn't, as the em++ version is generating less garbage than the c++ version.

I'm using -O3 for both em++ and g++, are there any other flags I can use in g++ to get similar optimizations?

Bye,
Mark

Alon Zakai

unread,
Jul 27, 2015, 6:41:50 PM7/27/15
to emscripten-discuss
Which version of gcc are you using? If you're not using the latest, then the difference might be that emscripten does use a recent LLVM.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Sibly

unread,
Jul 27, 2015, 6:43:42 PM7/27/15
to emscripte...@googlegroups.com
I'm on a mac mini, g++ --version is:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1

Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)

Target: x86_64-apple-darwin14.4.0

Thread model: posix


--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/yXE_YRD1Zus/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

Mark Sibly

unread,
Jul 27, 2015, 6:47:49 PM7/27/15
to emscripte...@googlegroups.com
...and em++ --version is:

emcc (Emscripten gcc/clang-like replacement) 1.34.1 ()

Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)

This is free and open source software under the MIT license.

There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(alas no llvm version there).

Alon Zakai

unread,
Jul 27, 2015, 6:49:30 PM7/27/15
to emscripten-discuss
That looks recent, so I suppose that's not the issue.

Other possibilities are that the browser's VM might happen to optimize something better than LLVM's codegen. Or that emscripten libc happens to be better at something, if you use any computationally intensive method there.

In general, emscripten+asm.js are about as fast as native code. It's not too surprising to hear that sometimes a native build is 30% faster or asm.js is 20% faster. That's the range of difference between native compilers themselves anyhow.

Hai h

unread,
Sep 12, 2016, 7:58:39 AM9/12/16
to emscripten-discuss
huy
Reply all
Reply to author
Forward
0 new messages