Interopping between asm.js/wasm and regular JS is slow, since it crosses the boundary of two different compilation paths/backends in the JS engine. If you want to create a array as quickly as possible and use it from JS side, the fastest way is to generate the whole array in asm.js side in a tight loop that doesn't allocate memory, and then hand off the whole resulting array to JS side (offset+length of the array on the heap to JS, and typedArray.set() to copy its contents from the heap). Any kind of interop code should not be present in the tight loop to get best performance possible.
2017-01-05 6:12 GMT+02:00 ExBigBoss <[email protected]>: > > > On Tuesday, January 3, 2017 at 11:45:22 AM UTC-8, Charles Vaughn wrote: >> >> Do you have example code? Using emscripten::val with strings will have a >> very high overhead in terms of moving strings into and out of the >> Emscripten heap. If you're just looking at exposing large homogenous arrays >> of int's/floats/doubles you can use ArrayBuffer based views into the >> Emscripten heap. >> >> On Thursday, December 29, 2016 at 5:12:36 PM UTC-8, ExBigBoss wrote: >>> >>> So today I was writing an embound module and all it really did was set >>> the i'th property of an emscripten::val with the i + 1'th value. This was >>> done in a for-loop and in vanilla JS, I used simple for-loop with the >>> native array and its push method. >>> >>> Basically, I just wanted to test how fast I could fill an array using >>> Emscripten vs vanilla JS. >>> >>> However, I noticed that my code was 10x slower using emscripten::val! >>> And this was done with the -O3 flag being set as well. Using the default >>> wrapper around std::vector, I was able to generate asm that was 3x as fast >>> as vanilla JS but unfortunately, it doesn't play well with the standard >>> vector. >>> >>> I'm really just wondering, has anybody else noticed poor performance >>> when Emscripten and external JS inter-operate with each other? >>> >> -- > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
