artoolkitx / jsartoolkit5

Javascript ARToolKit v5.x
https://artoolkitx.github.io/jsartoolkit5/examples/
Other
292 stars 69 forks source link

Wasm compilation with threads #88

Closed itamayo closed 4 years ago

itamayo commented 4 years ago

Hi !

First of all, great job you guys doing, congratz !

Any know if wasm is compiled with the flag theads enabled ? I have seen that chrome suports it and I wondering .. Thanks !

kalwalt commented 4 years ago

Hi !

First of all, great job you guys doing, congratz !

Any know if wasm is compiled with the flag theads enabled ? I have seen that chrome suports it and I wondering .. Thanks !

Hi @itamayo thank you! Jsartoolkit5 is not compiled with the thread flag. But I tried time ago in this PR https://github.com/kalwalt/jsartoolkit5/pull/2. This code is without WebWorker. We decide to go with the version without threads enabled because the Spectre issue at this time and because require an adittional flag option to enable in the browser. Maybe something is changed? Do you know if it is solved the Spectre issue?

itamayo commented 4 years ago

This code is without WebWorker. We decide to go with the version without threads enabled because the Spectre issue at this time and because require an adittional flag option to enable in the browser

I read last news about Spectre on web browser, seems Chrome is enabled again SharedArrayBuffer so Wasm could be used with Threads but still needs to enable a flag. Other browsers does not support SharedBufferArray ... I think you take a good decision. Anyway I am interested on webassembly performance with actived threads, so I will triy it, If I get any improvement I will share it ;)

kalwalt commented 4 years ago

I read last news about Spectre on web browser, seems Chrome is enabled again SharedArrayBuffer so Wasm could be used with Threads but still needs to enable a flag. Other browsers does not support SharedBufferArray ... I think you take a good decision.

i didn't know this. I think it is a recent decison. Remain the fact that the user needs to enable the SharedArrayBuffer flag in the Chrome Browser. (I think also Firefox support this option. ) But the question is: a normal user will do this? Anyway it will improve performances for sure, we have already tested this. If you want to try , i sugggest to you to start from my PR https://github.com/kalwalt/jsartoolkit5/pull/2 because the code in the master has not threading support, has modified functions wiyhout threading. And you will need to add the WebWorker, this i always would do but hadn't the time to give a try yet.... If you want post you result here or in my issue tracker repo. Good luck! :smile:

kalwalt commented 4 years ago

@itamayo can you point me also to a recent article where Chrome announce the SharedArrayBuffer support?

itamayo commented 4 years ago

It isn't recent but It says that with site-isolation sharedArrayBuffer is re-enabled. https://security.googleblog.com/2018/07/mitigating-spectre-with-site-isolation.html

kalwalt commented 4 years ago

@itamayo thank you!

subjectdenied commented 4 years ago

according to caniuse it is not yet available again, at least not for mobile chrome

kalwalt commented 4 years ago

@itamayo Instead using pthreads with wasm we should try the SIMD experimental feature https://v8.dev/features/simd you still need to enable a flag in the browser, but at least is not affected by the Spectre issue as i know. This doesn't require changes in the code, we could test with the master branch. The only prerequisites are, the upstream emscripten version and few changes in the compilation script.

itamayo commented 4 years ago

@kalwalt sorry I have been working hard I couldnt test pthreads solution deeply, a few test I did, didnt improve to much the actual wasm solution. The biggest isuue is that first tracking is take to long... I dont know if this is related pthreads, or is another type of botleneck, any idea? , I'll check about simd, thanks

kalwalt commented 4 years ago

Hi @itamayo we have start to test the SIMD for the NFT-Marker-Creator follow the discussion in this issue https://github.com/Carnaux/NFT-Marker-Creator/issues/33. Since the NFT-Marker-Creator is based on the Artoolkit5 lib every victory here will let transpose them to jsartoolkit5 more easily.