Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pthread initialization for 40 pthreads takes 5.8seconds because of 40 separate network roundtrips.. #21833

Closed
terop2 opened this issue Apr 25, 2024 · 11 comments

Comments

@terop2
Copy link

terop2 commented Apr 25, 2024

We expect pthreads initialization to fast, but currently it causes 5.8s delay to startup of our web page. Reason is that each pthread initialization requires separate network wide roundtrip. It would be better if the task would be done in 1 roundtrip for all 40 pthreads instead of 40 separate roundtrips executed sequentially that take HUGE amount of time.

The issue is completely invisibile on local machine. Need to have far distance machine available for debugging.

=> this feature makes pthreads completely unusable for our 3d engine.

@terop2
Copy link
Author

terop2 commented Apr 25, 2024

pthread_init

See this picture of pthread_init taking huge amount of time for 40 separate pthreads.

@terop2
Copy link
Author

terop2 commented Apr 25, 2024

pthreads taking this long time to initialize is completely unacceptable for a feature that saves only a little time further down the road.

@sbc100
Copy link
Collaborator

sbc100 commented Apr 25, 2024

Do you know which resource is being repeatedly fetched? Each worker does need to load the .js file.. but its always the same one so the browser should cache it.

I'm afraid I can't read anything in the picture you attached.. what is the pre-thread resource being fetched?

Can you try with version 3.1.58 that was recently released, it reduces the number of resources used per thread (although the overall amount of data needed is about the same).

Multi-threading is more expensive on the web than on native platforms due the current limitations of the platform so it unlikely we can get pthread start time close the native speed. However, I hope we can improve on where we are today.

@terop2
Copy link
Author

terop2 commented Apr 25, 2024

that resource is the web_page_highmem_worker.js file. i.e. it's emscripten's pthread system that causes the sequential delay.

@terop2
Copy link
Author

terop2 commented Apr 25, 2024

(it's possible we're using "no cache" flag enabled when we did the perf measurements, since that's the default in the network tab)

@sbc100
Copy link
Collaborator

sbc100 commented Apr 25, 2024

The good news is that we eliminated that .worker.js file completely in 3.1.58.. that file as fairly small though so I'm not sure it will have too much of an effect on the overall code size

@terop2
Copy link
Author

terop2 commented Apr 25, 2024

oh, I need to try the new versions if they work. I'm currently in 3.1.30 since the newer version had significant regression, but will need to try the new versions...

@terop2
Copy link
Author

terop2 commented Apr 26, 2024

I get some errors like: "error: expected top-level entity
1 | <U+0000>asm<U+0001><U+0000><U+0000><U+0000><U+0001><80><80><80><U+0000><U+0005><U+0002><U+007F><U+007F><U+0001><U+007F><U+0003><U+007F><U+007F><U+007F><U+0001><U+007F><U+0001><U+007F><U+0001><U+007F><U+0004><U+007F><U+007F><U+007F><U+007F><U+0001><U+007F>`<U+0003><U+007F><U+007F><U+007F><U+0000><U+0002><84><80><80><U+0000><U+000B><U+0003>env<U+000F>__linear_memory<U+0002><U+0000><U+0001><U+0003>env<U+000F>__stack_pointer<U+0003><U+007" from the new version of emscripten... :(

@terop2
Copy link
Author

terop2 commented Apr 26, 2024

got newest version of emscripten to work. Figured out that "static int foobar444=0;" to the top of the file will fix the top level entity problem in draco library. newer version looks otherwise ok, but debug console window dragging will give errors...

@terop2
Copy link
Author

terop2 commented Apr 26, 2024

thanks, this looks like its been solved already in newest emscripten... => proposing to close the issue

@kripken
Copy link
Member

kripken commented Apr 29, 2024

Great, closing.

@kripken kripken closed this as completed Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants