WebAssembly / WebAssembly/shared-everything-threads

"Solving" TLS by doing nothing

Open
#70 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
97
Forks
6
PR merge metrics
No merged PRs in 30d

Description

I've recently had a couple chats with the V8 team about TLS, and they're rightfully concerned about the necessary complexity, although not to the point of ruling anything out yet. They also made the astute observations that 1) shared functions are the root of all the complexity, as others have already pointed out, and that 2) implementing TLS in the engine ends up looking very much like implementing our current instance-per-thread model in the engine instead of user space.

This also led to the observation that at least for the multithreaded WasmGC use case, we could easily get away without shared functions by using instance-per-thread for functions and vtables and using vtable indices instead of vtable references in object instances. (Dart is in fact already using this strategy today.) That would also give us TLS "for free" in the same way we get TLS for free today, where each thread can simply have its own non-shared globals.

Ignoring shared functions for now is an excellent way to scope down complexity for prototypes and start trying to prove incremental value in the short term, but it leaves a couple problems unaddressed.

First, without shared functions, there can be no shared continuations. This would be very sad, especially for Kotlin, where shared continuations are extremely common at the source level. It's probably not a showstopper for them, though, since they can keep lowering the continuations to normal control flow as they do today.

Second, discarding shared functions and thread-local function imports does nothing to address the problem of Web engines having to support shared-to-unshared references to implement thread-bound data. We might be able to provide some short-term, incremental value without thread-bound data, but my hypothesis remains that we will need it in the long run. If that turns out to be true, then the marginal complexity of supporting shared functions and TLS, including thread-local functions, will be significantly reduced, although the performance questions will remain.

Finally, the non-Web folks who are primarily interested in this proposal so they can have threads without the instance-per-thread model would obviously be unhappy if we continued to require instance-per-thread.

So all in all, I don't think discarding shared functions is going to be the best long-term design, but it will make prototyping much simpler in the near future. We should certainly continue discussing how to effectively support shared functions, TLS, and shared continuations because those remain the biggest open questions we have for the long term.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue is a design discussion about shared functions, TLS, shared continuations, and instance-per-thread behavior in WebAssembly; no files, tests, or implementation entry points are named. Start by reviewing the proposal context and resolve the open design questions before attempting implementation, since the issue provides no concrete completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.