bytecodealliance / bytecodealliance/wasmtime

Wasmtime: avoid table lazy-init runtime checks on nullable funcref tables with null default

Open
#8,160 5 comments 1 reaction 0 assignees View on GitHub
performance wasmtime
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

From [this comment](https://github.com/bytecodealliance/wasmtime/pull/8158#issuecomment-2002601881): it would be great to have an optimization such that

> if a table's default funcref is null, don't do lazy-init, and make the 0 bit-pattern mean null rather than non-initialized-pointer-to-anyfunc.

This comes from a circumstance where we know we'll initialize a table slot manually before calling it (not doing so is a program error that should lead to a trap), possibly because we already have a branch for the case where it is null at the program-logic level (e.g. fallback IC). We still must trap on null somehow but #8159 can do that implicitly by detecting a segfault in a load from a `NULL` anyfunc pointer. The above optimization then means that we do not need the [lengthy lazy-init-check sequence](https://github.com/bytecodealliance/wasmtime/blob/7fa71a4f9e34bdb3ba85679d46e9a31a955fdd3a/crates/cranelift/src/func_environ.rs#L954-L1002) on loads from such tables, and we can do so without requiring any initialization at instantiation time either.

cc @alexcrichton @jameysharp

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.