WebAssembly / WebAssembly/shared-everything-threads
Question about thread-local function optimization
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 97
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Per the explainer, thread-local WA.Function starts as null on all threads and then transitions to non-null exactly once on a thread when the initialize method is called.
As an engine-internal optimization, setting a thread-local global to a thread-local function wrapper can skip a layer of indirection and set the global to refer directly to the bound function, since it will never change or be observed from another thread. This optimization only works because the dynamic contexts of thread-local globals and thread-local function wrappers are the same, i.e. an entire thread or agent.
How can the above be possible? When the global.set for a thread-local global happens, the initialize method may not have happened yet. From core wasm's perspective this is a non-null (ref func shared), so I don't think we can say that it traps due to null or type mismatch.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the explainer section describing thread-local WA.Function and the engine-internal optimization. Trace the interaction between initialize, global.set, nullability, and (ref func shared) in core WebAssembly. Done means resolving whether the optimization can be valid before initialize, with the proposal text or semantics clarified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100