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

[browser][MT] use regular POSIX portable threadpool #99836

Merged
merged 11 commits into from Mar 21, 2024

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Mar 15, 2024

Because we dispatch all interaction with JS to the thread which owns the JS objects,
we don't need to yield to browser event loop in the managed thread pool any more.

  • drop WebWorkerEventLoop
  • drop LowLevelLifoAsyncWaitSemaphore
  • drop mono_thread_platform_external_eventloop_keepalive_check
  • drop LowLevelLifoSemaphoreBase and _LifoSemaphoreBase

This is fine piece of machinery which I'm removing, but we don't need it for browser and it would be wasting time to maintain it.
I wonder if we will need to resurrect some of this for WASI, once preview 3 brings futures/promises. But I hope not and I hope that there would not be as strong thread affinity either.

Fixes #85052

@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-VM-threading-mono os-browser Browser variant of arch-wasm labels Mar 15, 2024
@pavelsavara pavelsavara added this to the 9.0.0 milestone Mar 15, 2024
@pavelsavara pavelsavara self-assigned this Mar 15, 2024
@pavelsavara pavelsavara requested a review from kouvel March 16, 2024 14:05
@pavelsavara pavelsavara marked this pull request as ready for review March 16, 2024 14:05
@pavelsavara
Copy link
Member Author

I filed #99888 for timeouts. I think it's not related to this PR, but I will explore further.

Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth keeping the async semaphore around. But I suppose we can always revert that part, if there is a need in theb future.

Threadpool changes lgtm.

Part of the work here originally was slicing up the event loop into multiple functions and files. @kouvel , would you prefer everything back into a single giant function, or no?

src/mono/mono/metadata/threads.c Show resolved Hide resolved
@kouvel
Copy link
Member

kouvel commented Mar 18, 2024

Part of the work here originally was slicing up the event loop into multiple functions and files. @kouvel , would you prefer everything back into a single giant function, or no?

It would be nice to clean up some things if they're not necessary anymore (from a4e2609, dcb34de, 042f593). Eg:

  • If PortableThreadPool.WorkerThread.CreateWorker.cs is not expected to be needed anymore, the code could be folded into PortableThreadPool.WorkerThread.cs and maybe also undoing some of the refactoring if it's not expected to be needed
  • Similarly, if LowLevelLifoSemaphoreBase.cs is not expected to be needed anymore, the code could be folded into LowLevelLifoSemaphore.cs

Anyway, the thread pool changes LGTM aside from some cleanup that could be done.

@pavelsavara
Copy link
Member Author

some cleanup that could be done.

Moved code back, no functional change. (apart from the first commit here which changes Browser TP)

@kouvel
Copy link
Member

kouvel commented Mar 20, 2024

Moved code back, no functional change. (apart from the first commit here which changes Browser TP)

Thanks! Just left one minor suggestion but otherwise the moves LGTM.

@pavelsavara pavelsavara merged commit d9b9eb9 into dotnet:main Mar 21, 2024
158 of 161 checks passed
@pavelsavara pavelsavara deleted the browser_mt_portable_thread_pool branch March 21, 2024 15:50
@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-VM-threading-mono os-browser Browser variant of arch-wasm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[browser][MT] Keep track of additional JS keepalive sources for worker threads
3 participants