Files
wasmtime/crates/runtime/Cargo.toml
Alex Crichton d4b54ee0a8 More optimizations for calling into WebAssembly (#2759)
* Combine stack-based cleanups for faster wasm calls

This commit is an extension of #2757 where the goal is to optimize entry
into WebAssembly. Currently wasmtime has two stack-based cleanups when
entering wasm, one for the externref activation table and another for
stack limits getting reset. This commit fuses these two cleanups
together into one and moves some code around which enables less captures
for fewer closures and such to speed up calls in to wasm a bit more.
Overall this drops the execution time from 88ns to 80ns locally for me.

This also updates the atomic orderings when updating the stack limit
from `SeqCst` to `Relaxed`. While `SeqCst` is a reasonable starting
point the usage here should be safe to use `Relaxed` since we're not
using the atomics to actually protect any memory, it's simply receiving
signals from other threads.

* Determine whether a pc is wasm via a global map

The macOS implementation of traps recently changed to using mach ports
for handlers instead of signal handlers. This means that a previously
relied upon invariant, each thread fixes its own trap, was broken. The
macOS implementation worked around this by maintaining a global map from
thread id to thread local information, however, to solve the problem.

This global map is quite slow though. It involves taking a lock and
updating a hash map on all calls into WebAssembly. In my local testing
this accounts for >70% of the overhead of calling into WebAssembly on
macOS. Naturally it'd be great to remove this!

This commit fixes this issue and removes the global lock/map that is
updated on all calls into WebAssembly. The fix is to maintain a global
map of wasm modules and their trap addresses in the `wasmtime` crate.
Doing so is relatively simple since we're already tracking this
information at the `Store` level.

Once we've got a global map then the macOS implementation can use this
from a foreign thread and everything works out.

Locally this brings the overhead, on macOS specifically, of calling into
wasm from 80ns to ~20ns.

* Fix compiles

* Review comments
2021-03-24 11:41:33 -05:00

52 lines
1.3 KiB
TOML

[package]
name = "wasmtime-runtime"
version = "0.25.0"
authors = ["The Wasmtime Project Developers"]
description = "Runtime library support for Wasmtime"
documentation = "https://docs.rs/wasmtime-runtime"
license = "Apache-2.0 WITH LLVM-exception"
categories = ["wasm"]
keywords = ["webassembly", "wasm"]
repository = "https://github.com/bytecodealliance/wasmtime"
readme = "README.md"
edition = "2018"
[dependencies]
wasmtime-environ = { path = "../environ", version = "0.25.0" }
wasmtime-fiber = { path = "../fiber", version = "0.25.0", optional = true }
region = "2.1.0"
libc = { version = "0.2.82", default-features = false }
log = "0.4.8"
memoffset = "0.6.0"
indexmap = "1.0.2"
thiserror = "1.0.4"
more-asserts = "0.2.1"
cfg-if = "1.0"
backtrace = "0.3.55"
lazy_static = "1.3.0"
rand = "0.8.3"
anyhow = "1.0.38"
[target.'cfg(target_os = "macos")'.dependencies]
mach = "0.3.2"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.7", features = ["winbase", "memoryapi", "errhandlingapi"] }
[target.'cfg(target_os = "linux")'.dependencies]
userfaultfd = { version = "0.3.0", optional = true }
[build-dependencies]
cc = "1.0"
[badges]
maintenance = { status = "actively-developed" }
[features]
default = []
async = ["wasmtime-fiber"]
# Enables support for userfaultfd in the pooling allocator when building on Linux
uffd = ["userfaultfd"]