bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.37k stars 1.3k forks source link

Performance issue related to increment operation in nested loops #7733

Open ShuyaoJiang opened 10 months ago

ShuyaoJiang commented 10 months ago

Summary

Hi, I ran the attached case (C program, compiled to Wasm by Emscripten) in different Wasm runtimes, and found abnormal performance in Wasmtime compared with other runtimes. The execution time of this case (time interval from the start to the end of the execution of Wasm bytecode running command) on different runtimes is as follows:

We found that in most other test cases, Wasmtime can achieve similar performance (1-2x) with the other two runtimes. However, in this case, Wasmtime is about 10x slower than the other two runtimes.

Emscripten

Wasm Runtime Version

Hardware & OS

Additional details

The attached source program is synthesized by a Csmith seed and a code snippet from another program. The inserted code snippet is on lines 2386-2388 of the source program, which is an increment operation in nested loops. So, we think that this abnormal performance may be caused by this operation. Could you please check this situation? Thank you!

1702317926850.zip

tschneidereit commented 10 months ago

Hi @ShuyaoJiang, thank you for filing this and the other performance issues, much appreciated!

Would it be possible to also share (for this and the other issues you filed) the exact commands you used to compile the code, and also to execute the resulting .wasm file in all of the runtimes? That'd greatly help us in investigating what's going on.

ShuyaoJiang commented 10 months ago

Hi, here are the commands I used:

Compile

Execute .wasm file (the execution time is collected in this phase)

fitzgen commented 10 months ago

This is measuring compilation time as well, you can separate the phases via

$ wasmtime compile foo.wasm
$ wasmtime run --allow-precompiled foo.cwasm

When you separate the compilation and execution phases are you still seeing Wasmtime as 10x slower?

alexcrichton commented 9 months ago

Ok I've dug into this in the same manner as https://github.com/bytecodealliance/wasmtime/issues/7732#issuecomment-1909132554 and I've at least locally confirmed that v8 takes ~2ms to execute this file and Wasmtime takes ~350us. In that sense I suspect that the 100ms+ times reported in the OP were probably including the compilation time for the module.

I'm hesitant to go ahead and close this to ensure you can confirm that when separating out the compilation phase you get expected timings, however.