Massive performance loss in Firefox on "reset" of a emscripten program

125 views
Skip to first unread message

Chris

unread,
Feb 10, 2014, 6:04:30 AM2/10/14
to emscripte...@googlegroups.com
Hi all,
I ported a fluid simulation C++ code (command line program) with emscripten and it works quite fantastic. I never thought JS could run that efficiently.
However, to re-run my program I wrapped the compiled version in a function (with pre/post.js) to reset its state. That usually worked nice, but recently I get at first an awesome performance from FF (~0.3 native speed!), but after a reset it suffers a drastic performance breakdown of a factor of 20.

The site is http://gaia.respawned.com

You can observe it just by clicking "Run" in the Run tab, the sparse matrix mul+add performance is measured thoroughly. At first run:
Performance (mul+add): 0.377445 GFlops

After "Reset" (calling gaia_create() again in the worker):
Performance (mul+add): 0.0187213 GFlops

On a recent Chrome I do not get a difference, always around 0.26 GFlops.

Thanks for your help,
Christian

PS: Native gcc -O3 : 1.17 GFlops.




Alon Zakai

unread,
Feb 10, 2014, 1:21:07 PM2/10/14
to emscripte...@googlegroups.com
Does it print out the GFlops somewhere?

All I see is "Execution took", which went from 1.628 to 2.172 when I reset.

- Alon



--
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/groups/opt_out.

Chris

unread,
Feb 10, 2014, 2:13:28 PM2/10/14
to emscripte...@googlegroups.com
Yes - you have to switch to the "Run"tab first. That is where the CFD sim task is controlled, the gnuplot tasks may/should suffer from the same problem. 
The GFlops output comes after the first time step.

Cheers,
C
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Alon Zakai

unread,
Feb 10, 2014, 4:17:01 PM2/10/14
to emscripte...@googlegroups.com
Thanks. How long should this run? I waited until TS: 100 and it still keeps going it seems.

I see an asm.js validation error in the log, this could be related to the performance problem. Was this compiled using latest emscripten? If so, can you make a whitespace-friendly build I could take a look at? emcc -g1 will do that. (Even better is if you can provide the bitcode file, but not necessary.)

- Alon



To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

Christian H

unread,
Feb 11, 2014, 3:50:09 AM2/11/14
to emscripte...@googlegroups.com
Hi Alon,
I did recompile with the latest emscripten, the one I compiled with was not more than 2 months old. However, now I get nothing. I do see the asm.js warnings, but no reaction to Module.run(), also no error (even within worker triggering manually), the FS works, Module.print() works too. That happens to all versions I compiled with -O2 or -g1. I prepared a site loading the new (-g1) version:


The bitcode is at

You don't need to wait that long, it will run until TS 1000. The performance line appears after TS 0. 

Thanks,
Christian


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/UFL7YRfvJQw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

Christian H

unread,
Feb 11, 2014, 3:55:21 AM2/11/14
to emscripte...@googlegroups.com
...just noticed that chrome does complain about FS.deleteFile() not found? How do I remove a file now?

Cheers,
C

Alon Zakai

unread,
Feb 11, 2014, 1:32:03 PM2/11/14
to emscripte...@googlegroups.com
I believe FS.unlink is what does that.

- Alon

Chris

unread,
Feb 12, 2014, 10:22:26 AM2/12/14
to emscripte...@googlegroups.com
Fixed, but it wasn't actually the problem. For some reason Module.calledRun was true, so Module.run() did nothing. Setting it now manually false before the run.
To the original problem: The -g1 version works now (index_alon.html), without asm.js errors but is ~100 times slower. I guess this is no use in determining why the speed loss occurred. Should I compile with -O2 and -g1 ?

Thanks,
Christian
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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/UFL7YRfvJQw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Alon Zakai

unread,
Feb 12, 2014, 2:38:49 PM2/12/14
to emscripte...@googlegroups.com
Looking in src/postamble.js, calledRun is only set to true when actually running this code:

    ensureInitRuntime();

    preMain();

    if (Module['_main'] && shouldRunNow) {
      Module['callMain'](args);
    }

    postRun();

so if you do not throw in any of those (you would see an exception), or do not define Module._main at a later time, this should work. (There is also shouldRunNow, which unless you defined INVOKE_RUN or Module['noInitialRun'], should not interfere here.) Hope that helps figure out that issue.

Yes, for performance -O2 -g1 is needed.

- Alon



To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

Chris

unread,
Feb 12, 2014, 4:55:15 PM2/12/14
to emscripte...@googlegroups.com
Hi Alon,

Module.calledRun is set true by doRun() simply if Module.setStatus does not exist... This is the code em++ appends before post.js:

  if (Module['setStatus']) {
    Module['setStatus']('Running...');
    setTimeout(function() {
      setTimeout(function() {
        Module['setStatus']('');
      }, 1);
      if (!ABORT) doRun();
    }, 1);
  } else {
    doRun();
  }

I compiled now with latest emscripten -O2 -g1, no asm.js error (ignore the ones coming from gnuplot.js), but the performance bug after a reset remains. :(
The new version is uploaded directly at

"Reset" simply calls gaia_create() again in the worker. Is there a way to open a worker console in the inspector of FF? This is a pretty handy feature in chrome...

Cheers,
C
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/UFL7YRfvJQw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Alon Zakai

unread,
Feb 12, 2014, 7:02:42 PM2/12/14
to emscripte...@googlegroups.com
I don't follow? Yes, if there is no setStatus, then it will call doRun, and doRun will both set calledRun to true but also actually call _main, so main must end up being called.

Which branch of emscripten are you on btw? And when did you last update? Perhaps we are looking at different code?

- Alon



To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

Alon Zakai

unread,
Feb 12, 2014, 7:11:30 PM2/12/14
to emscripte...@googlegroups.com
Not sure what I'm doing wrong regarding performance... starting to feel like I am an idiot here.

1. I do *not* see it pass asm.js validation. I see two messages,

Successfully compiled asm.js code (loaded from cache in 13ms) gaia.js
TypeError: asm.js type error: void incompatible with previous return of type signed

One is for gaia.js, another for gnuplot.js. Which is being benchmarked here?

2. I go to the run tab, and press run. It very quickly prints out GFlops. Is that the only number I care about here? All the further work is irrelevant to this bug report?

Then I press reset, but nothing much happens. I get more output, but no more mentions of GFlops - what should I be comparing here?

- Alon


Chris

unread,
Feb 16, 2014, 10:00:30 AM2/16/14
to emscripte...@googlegroups.com
Hi Alon,

I am on the master branch. I probably don't understand the starting mechanisms. On loading, I do not want the program (main) to be called, so I set shouldRunNow and noInitialRun to false, without truly understanding what it means. Because I have no setStatus, doRun gets called but not main, so for the intended run later I have to set calledRun to false because main was actually never called. 

The performance bug is probably fixing itself in the future.I should have given you a more detailed description earlier, sorry for that. 
Checking the console log in FF for the second run I found the following line that probably explains everything:
--
[15:54:06.745] asm.js link error: As a temporary limitation, modules cannot be linked more than once. This limitation should be removed in a future release. To work around this, compile a second module (e.g., using the Function constructor). @ http://gaia.respawned.com/gaia.js:98973


Not necessary anymore, but here are the steps to reproduce this. 
The fluid simulation is using the time-steps as main loop. 
- goto http://gaia.respawned.com wait until you see the gnuplot graph.
- switch to the "Run" tab and hit Start
- wait for two time steps, performance output always comes after TS 0. 
- now hit "Pause", wait a few seconds (time step needs to finish)
- click "Reset", this will call the encapsulated compiled version again in the worker.
- click "Run" again and wait again for the first two time steps to finish. (it will take a lot longer now)

Cheers,
C

Alon Zakai

unread,
Feb 16, 2014, 2:00:22 PM2/16/14
to emscripte...@googlegroups.com
Ok, yes, that error message does explain the difference. I still don't understand what I was doing wrong before that I didn't see perf numbers and/or that message, but looks like now we understand the issue. I think this is a temporary limitation which will eventually be fixed, but the workaround isn't hard to do either.

- Alon



Reply all
Reply to author
Forward
0 new messages