Skip to content
Alon Zakai edited this page Sep 28, 2015 · 2 revisions

Memory Growth

asm.js has a memory growth option (-s ALLOW_MEMORY_GROWTH=1 in emcc), which is supported in Firefox and Edge. In Chrome, there is currently a large slowdown due to

https://code.google.com/p/v8/issues/detail?id=3907

Workaround: Disable asm.js validation, by removing "use asm" manually or building with -s ASM_JS=2. Downside: Disabling asm.js makes the game run slower in almost all browsers (at least Chrome, Firefox and Edge).

Float32

-s PRECISE_F32=1 enables proper 32-bit float semantics, using Math.fround. This is fast in Firefox and Edge, but in Chrome it has not been fully optimized yet, and is slower than without PRECISE_F32,

https://code.google.com/p/v8/issues/detail?id=3589

Workaround: Do not build with PRECISE_F32. Downsides: You need to make sure your app runs properly despite using doubles for floats (i.e., your floats will have the precision of doubles, and so different rounding behavior). Also does not benefit from speedups which are possible in other browsers.

A possible workaround could have been to build to HTML with -s PRECISE_F32=2. That generates code in the .html file that checks if Math.fround is present, and dynamically removes it from the codebase if not. However, this is no longer an option for 2 reasons:

  • Chrome does have Math.fround, it just isn't fully optimized. We don't have a good way to find out if it's worth using fround or not, except to check "is this Chrome?" which is of course a bad idea.
  • Chrome detects "use asm" and optimizes code differently, and when we dynamically remove those frounds, the output is not necessarily validating asm.js. This would need to be tested carefully and possibly require additional work.