-
Hi fellow Emscripten users, we are trying to make use of multi threading in an application which gets called from JS, does some longer running calculations (think of a big for loop) and returns the result back to JS. Now we observed that just enabling pthreads (we also use simd, Is this expected? Is there a rather big overhead for just having pthread support activated? We don't have exception support enabled and it seems there is no difference between static/dynamic memory size. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 15 replies
-
Just enabling pthreads has the effect of making various things use actual locks (like malloc, file operations, etc.). Also atomic operations are actually atomic. Both of those slowdowns happen even if you never create another thread. A 10% slowdown is more than I'd expect, though, so it might be interesting to profile in the browser devtools and see how the profiles differ between the two builds - that diff could show interesting things. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip and your time. As you thought, seems it is With
|
Self Time | Total Time | Activity |
---|---|---|
850.0 ms, 4.8 % | 850.0 ms, 4.8 % | a_swap.1 |
687.1 ms, 3.9 % | 1684.8 ms, 9.5 % | dlfree |
684.0 ms. 3.9 % | 684.0 ms, 3.9 % | a_cas.3 |
599.3 ms. 3.4 % | 1622.1 ms, 9.1 % | dlmalloc |
Without pthread
in web worker.
Self Time | Total Time | Activity |
---|---|---|
591.9 ms, 4.0 % | 591.9 ms, 4.0 % | dlfree |
490.4 ms, 3.3 % | 491.0 ms, 3.3 % | dlmalloc |
Beta Was this translation helpful? Give feedback.
-
@kripken I understand this discussion has been resolved. Please let me know if I should start another topic. I just recently enabled PThreads in my application and am currently hitting into the above performance degradation. Just wanted to check if there's anything that I can do or try out. |
Beta Was this translation helpful? Give feedback.
Just enabling pthreads has the effect of making various things use actual locks (like malloc, file operations, etc.). Also atomic operations are actually atomic. Both of those slowdowns happen even if you never create another thread.
A 10% slowdown is more than I'd expect, though, so it might be interesting to profile in the browser devtools and see how the profiles differ between the two builds - that diff could show interesting things.