bytecodealliance / bytecodealliance/wasmtime

Wasmtime should optimize away atomic operations when memory is not shared

Open
#4,250 0 comments 0 reactions 0 assignees View on GitHub
wasm-proposal:threads
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

Part of the threads proposal in wasm is to add a "shared" flag to memory. Wasmtime statically knows that if a memory is not shared then atomic operations are not necessary because the memory cannot be concurrently modified. The atomic rmw instructions added in the threads proposal work on all memories, however.

Wasmtime should translate the atomic operations differently depending on whether the memory they're referencing is shared or not, automatically falling back to non-atomic operations on non-shared memories. While this isn't a huge concern today if threads become more prevalent in the wasm tooling ecosystem it might be more common to use atomic operations unconditionally regardless of whether memory is shared or not. For example the Rust `wasm32-wasi` target could perhaps one day use a real implementation for mutexes so whether or not memory is shared is a link-time flag rather than a build-time flag as it is today. In this situation it'll likely be faster for Wasmtime to use non-atomic operations instead of atomic operations when memory isn't shared.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.