Backport the pure-JS improvements from the emscripten-ify branch for a more fair comparison.