bytecodealliance / bytecodealliance/wasmtime

Changing a stored value from 1 to 0 makes suspicion performance decreasing

Open
#9,590 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

## Test Cases

[case.zip](https://github.com/user-attachments/files/17690564/case.zip)

## Steps to Reproduce
Hi, I run the attached two cases(`good.wasm` & `bad.wasm`) in `Wasmtime` and `WasmEdge`(AOT), and collect their execution time respectively (measured by `time` tool).

```bash
# command to collect execution time of wasmtime
wasmtime compile bad.wasm -o bad.cwasm
time wasmtime run --allow-precompiled bad.cwasm

# command to collect execution time of wasmedge
wasmedgec bad.wasm bad-wasmedge-aot.wasm
time wasmedge bad-wasmedge-aot.wasm
```

## Expected Results & Actual Results
For `good.wasm`, the execution time in different runtimes are as follows:

- `Wasmtime`: 0.99s
- `WasmEdge`: 1.06s

For `bad.wasm`, the execution time in different runtimes are as follows:

- `Wasmtime`: 6.57s
- `WasmEdge`: 1.05s

The difference between the attached two cases is as follows: changing the stored value in line 8 from `1` to `0`, which decreases Wasmtime performance by 5.5s but has no negative effect on WasmEdge.

```bash
➜ diff diff good.wat bad.wat
8c8
< f64.const 0x1p+0 (;=1;)
---
> f64.const 0x0p+0 (;=0;)
```

## More observations & questions:
1. The store operation is outside the loop, and the following instructions do not contain any load operations.
2. `Wasmtime` compiles the loop conditions in `bad.wasm` and `good.wasm` in different ways, but I don't understand why the changes of an instruction that seems unrelated to the loop can affect the compilation strategies to the loop.

```bash
# part of machine code of bad.wasm generated by wasmtime
...
jne 5c
movdqu (%rsp),%xmm1
jmp 60
...
je 7f
movdqu %xmm1,(%rsp)
jmp 46
...
je a2
movdqu %xmm1,(%rsp)
jmp 46
...

# part of machine code of good.wasm generated by wasmtime
...
je 5f
...
jne 4f
...
jne 4f
...

```

## Versions and Environment
- Wasmtime version or commit: c8b136965
- Operating system: Linux ringzzz-OptiPlex-Micro-Plus-7010 6.5.0-18-generic
- Architecture: Intel(R) Core(TM) i5-13500

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.