Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scenario with very slow function execution in Wasmer on Windows compared to other runtimes and a native app #2260

Closed
dsherret opened this issue Apr 25, 2021 · 8 comments · Fixed by #2666
Assignees
Labels
bug Something isn't working 📦 lib-vm About wasmer-vm priority-high High priority issue
Milestone

Comments

@dsherret
Copy link
Contributor

dsherret commented Apr 25, 2021

Describe the bug

Usually wasmer is pretty quick, but I have a scenario where it's way way slower than browsers and a native rust app.

  • wasmer 1.0.2 (cranelift)
  • rustc 1.51.0 (2fd73fabe 2021-03-23)
  • x86_64
  • Edit: Windows 10 (19042.928) -- I haven't been able to reproduce on linux or mac.

Steps to reproduce

Reproduction steps available in https://github.com/dsherret/slow-wasm-example

Expected behavior

Would at least expect it to execute somewhere close to chrome (I would hope it would be close to wasmtime though).

Actual behavior

On my machine:

  • Native - ~700ms
  • Wasmer (cranelift) - 145s
  • Wasmtime - 711ms
  • Chrome - 5s
  • Firefox - 705ms

This may be because the code is doing many allocations via bumpalo, but usually it's pretty quick...

@dsherret dsherret added the bug Something isn't working label Apr 25, 2021
@dsherret dsherret changed the title Scenario with very slow function execution in Wasmer compared to browsers and a native app Scenario with very slow function execution in Wasmer compared to other runtimes and a native app Apr 25, 2021
@k-nasa
Copy link
Contributor

k-nasa commented Apr 26, 2021

I couldn't reproduce it in my environment...

Enviroment

❯ echo "`wasmer -V` | `rustc -V` | `uname -m`"
wasmer 1.0.2 | rustc 1.53.0-nightly (42816d61e 2021-04-24) | x86_64

Results

  • native 667ms
  • wasmtime 655ms
  • wasmer 969ms
  • chorme 1539ms
  • firefox 686ms

native

~/lab/oss/sandbox/slow-wasm-example/native-app main*
❯ cargo run --release
    Finished release [optimized] target(s) in 0.01s
     Running `target/release/native-app`
1317605
Finished in 667ms...

wasmtime

~/lab/oss/sandbox/slow-wasm-example/wasmtime-app main*
❯ cargo run --release
    Finished release [optimized] target(s) in 0.08s
     Running `target/release/wasmtime-app`
Finished in 655ms...
Result: 1317605

wasmer

~/lab/oss/sandbox/slow-wasm-example/wasmer-app main*
❯ cargo run --release
    Finished release [optimized] target(s) in 0.07s
     Running `target/release/app`
Starting...
Finished in 969ms...
Result: I32(1317605)

Chrome

スクリーンショット 2021-04-27 8 51 35

Firefox

スクリーンショット 2021-04-27 8 51 01

@dsherret
Copy link
Contributor Author

@k-nasa interesting! Maybe it only occurs on Windows (I will try out on other OS later). I'm on Windows 10 (19042.928)

@dsherret dsherret changed the title Scenario with very slow function execution in Wasmer compared to other runtimes and a native app Scenario with very slow function execution in Wasmer on Windows compared to other runtimes and a native app Apr 27, 2021
@dsherret
Copy link
Contributor Author

Yes, it only seems to occur on windows. I just tried on linux, mac, and two different windows machines. I've updated the description and title.

@k-nasa
Copy link
Contributor

k-nasa commented Apr 27, 2021

I want to try this problem, but I don't have windows machine...

@syrusakbary
Copy link
Member

syrusakbary commented Apr 30, 2021

I believe the latest PR refactoring traps (#2216) and Cranelift fix (#2224) will fix the issue. Although we need to merge #2250 (in progress) #2272 (in progress) first.

I'll keep the issue updated with the progress!

@Hywan Hywan added the 📦 lib-vm About wasmer-vm label Jul 17, 2021
@Amanieu Amanieu added the priority-high High priority issue label Oct 20, 2021
@wchaudry wchaudry added this to the Wasmer Runtime 2.x milestone Oct 21, 2021
@wchaudry wchaudry assigned Amanieu and unassigned syrusakbary Oct 28, 2021
@syrusakbary syrusakbary added the 🕵️ needs investigation The issue/PR needs further investigation label Nov 3, 2021
@Amanieu Amanieu assigned ptitSeb and unassigned Amanieu Nov 5, 2021
@ptitSeb
Copy link
Contributor

ptitSeb commented Nov 8, 2021

I reproduce the issue, even with current wasmer codebase.

I made some profiling, and it seems the cause is an excessive amount of memcpy beeing called. Mostly from core::intrinsics::copy_nonoverlapping<u8>
Those calls seems to be done from the JIT'd code for the most part, with memory_grow beeing the culprit

image

@syrusakbary
Copy link
Member

@syrusakbary syrusakbary removed the 🕵️ needs investigation The issue/PR needs further investigation label Nov 8, 2021
bors bot added a commit that referenced this issue Nov 8, 2021
2666: fix(windows) Fix slow memory grow handling (fix #2260) r=Amanieu a=ptitSeb

# Description
Fix slowiness on Windows plateforms with "memory grow".

Will fix #2260 and should speedup Windows use in general.

Co-authored-by: ptitSeb <[email protected]>
bors bot added a commit that referenced this issue Nov 8, 2021
2666: fix(windows) Fix slow memory grow handling (fix #2260) r=ptitSeb a=ptitSeb

# Description
Fix slowiness on Windows plateforms with "memory grow".

Will fix #2260 and should speedup Windows use in general.

2668: Fix time format spec in debug output r=ptitSeb a=Amanieu

`%Z` is not a valid specifier for the `time` crate, it should be `%z` instead. This was causing panics in debug builds.

Co-authored-by: ptitSeb <[email protected]>
Co-authored-by: Amanieu d'Antras <[email protected]>
@bors bors bot closed this as completed in 8f035d8 Nov 8, 2021
@dsherret
Copy link
Contributor Author

dsherret commented Dec 5, 2021

Thanks a lot! I can confirm it is fixed and super fast now in 2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-vm About wasmer-vm priority-high High priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants