Skip to content

[browser][MT] Multithreading and JavaScript async interop in .NET 9 #85592

Closed
@lambdageek

Description

@lambdageek

Tracking issue for further work on JS interop and multithreading.

Constituent part of #76956

Goals

  • CPU intensive workloads on dotnet thread pool
  • Allow user to start new managed threads using new Thread and join it.
  • Add new C# API for creating dedicated web workers with JS interop. Allow JS async/promises via external event loop.
  • enable blocking Task.Wait and lock() like APIs from C# user code on all threads or non-JS/UI threads
    • Current public API throws PNSE for it
    • This is core part on MT value proposition.
    • If people want to use existing MT code-bases, most of the time, the code is full of locks.
    • People want to use existing desktop/server multi-threaded code as is.
  • allow HTTP and WS C# APIs to be used from any thread despite underlying JS object affinity
  • JSImport/JSExport interop in maximum possible extent.
  • don't change/break single threaded build. †

Lower priority goals

  • try to make it debugging friendly
  • sync C# to async JS
    • dynamic creation of new pthread
    • implement crypto via subtle browser API
    • allow MonoVM to lazily download DLLs from the server, instead of during startup.
    • implement synchronous APIs of the HTTP and WS clients. At the moment they throw PNSE.
  • sync JS to async JS to sync C#
    • allow calls to synchronous JSExport from UI thread (callback)
  • don't prevent future marshaling of JS transferable objects, like streams and canvas.
  • offload CPU intensive part of WASM startup to WebWorker, so that the pre-rendered (blazor) UI could stay responsive during Mono VM startup.

Non-goals

  • interact with JS state on WebWorker of managed threads other than UI thread or dedicated JSWebWorker

Design discussion and experiment

Depending on selected design

Bugs

Memory growth, alignment

Broken tests

Nice to have

Progress

Future

Metadata

Metadata

Labels

arch-wasmWebAssembly architecturearea-VM-threading-monoos-browserBrowser variant of arch-wasmtrackingThis issue is tracking the completion of other related issues.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions