emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.8k stars 3.31k forks source link

Huge difference of performance between Opera and Chrome #503

Closed Ikspay closed 12 years ago

Ikspay commented 12 years ago

Hi,

I have compiled a library which makes image processing on a video with Emscripten to test it on the video get by getUserMedia() in HTML5 and I encounter a big difference of performance between Opera and Chrome.

I've displayed the time by image to see the difference like that :

        // Start the clock
    var elapsed_time = (new Date()).getTime();

        // call to emscripten compiled function
    res = __Z24MyFunctioniiiiiPc(w, h, nc, d, ws, id);

    // Stop the clock
    time_dump.innerHTML = "Time by Image : " + ((new Date()).getTime() - elapsed_time).toString() + "ms";

And on Opera I get an average of 40ms, whereas on Chrome I get an average of 700ms !!!

The only difference in the javascript is that Opera access the webcam video with

navigator.getUserMedia({video: true, audio: false}, onSuccess, onError);

And Chrome uses

navigator.webkitGetUserMedia({audio:false, video:true}, onSuccess, onError);

Is it normal that I get such a difference between those two browsers ? Does that come from Emscripten or should I look elsewhere ?

Regards,

Ikspay.

Ikspay commented 12 years ago

Well, I have just recompiled the library using the -O2 tag, and the problem has disappeared.

Now I have about 20 to 30ms on both Opera and Chrome.

This problem seems to occur only when using -O1 tag or no tag at all.

If you have any information or idea about why is it occuring, I'd be glad to hear it !

Regards,

Ikspay.

kripken commented 12 years ago

The problem is that some browsers do not run unoptimized code well - they need native loop recreation (relooping, which is done in -O2). -O2 should run well in almost all modern browsers.