I have read lots about how fast Emscripten code can be, thus I decided to convert my js application to C++ and then compile to Emscripten. I got about +30% speed increase and it's not the thing I expected! (I thought it will be at least 5x speed increase) So I decided to check the compiled code and I saw this strange thing!
This is an original method code (C++, but it looks almost the same in the original "slow" JS application).
void Op2B()
{
sm = (sm - 1) & 65535;
t->time += 2;
}
This is an emscripten-compiled asm.js version of the same code
function __ZN16EpsilonGames_VGS3Z804Op2BEv($0) {
$0 = $0|0;
var $1 = 0, $10 = 0, $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0, label = 0, sp = 0;
sp = STACKTOP;
STACKTOP = STACKTOP + 16|0; if ((STACKTOP|0) >= (STACK_MAX|0)) abortStackOverflow(16|0);
$1 = $0;
$2 = $1;
$3 = ((($2)) + 24|0);
$4 = load4($3);
$5 = (($4) - 1)|0;
$6 = $5 & 65535;
$7 = ((($2)) + 24|0);
store4($7,$6);
$8 = load4($2);
$9 = load4($8);
$10 = (($9) + 2)|0;
store4($8,$10);
STACKTOP = sp;return;
}
As you can see, It's far away from being optimal.
Is there any possibility to make this code a bit more optimal? I still hope to get at least x5 increase in speed.
Thanks!