bytecodealliance / bytecodealliance/wasmtime

Figure out how to optimize away `global.set`/`.get` of component flags and `trapnz`s in fully inlined cross-component function calls

Open
#11,340 5 comments 0 reactions 0 assignees View on GitHub
cranelift:goal:optimize-speed wasm-proposal:component-model
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

For example, consider `tests/disas/component-model/direct-call-inlining.wat`. It begins by checking and setting the component flag globals for entry into a component:

https://github.com/bytecodealliance/wasmtime/blob/6b7465480b6fc831dad1b9dfad09b7cf58a05bd3/tests/disas/component-model/direct-adapter-calls-inlining.wat#L80-L100

And ends by resetting those globals to their original values:

https://github.com/bytecodealliance/wasmtime/blob/6b7465480b6fc831dad1b9dfad09b7cf58a05bd3/tests/disas/component-model/direct-adapter-calls-inlining.wat#L104-L133

This is the vast bulk of the inlined callee code, since the actual callee got const-prop'd away into a simple constant:

https://github.com/bytecodealliance/wasmtime/blob/6b7465480b6fc831dad1b9dfad09b7cf58a05bd3/tests/disas/component-model/direct-adapter-calls-inlining.wat#L143

Ideally the only thing we would have after inlining is that constant. I guess we also need to check the flags, but we shouldn't need to write to them at all.

Addressing this likely involves implementing [dead-store-elimination](https://github.com/bytecodealliance/wasmtime/issues/4167) in our alias analysis, but maybe also requires some higher-level analyses and logic in the adapter generation code as well, where we know exactly what can and cannot observe those globals and when.

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.