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

fix slow compilation by using dynasm VecAssembler #71

Closed
wants to merge 6 commits into from

Conversation

ailisp
Copy link
Member

@ailisp ailisp commented Nov 10, 2021

Compile was slow, especially for many function contracts because it use dynasm Assembler, which doing a few system call per wasm function. These system calls are about memory management (mmap, munmap, mprotect), but these are not used by wasmer at all (great finding by @matklad !). Drop them make compilation 10x faster:

Before ( 093eb59 ):

cargo run --release -p wasmer-workspace --example compiler-singlepass --features singlepass
    Finished release [optimized] target(s) in 0.12s
     Running `target/release/examples/compiler-singlepass`
code.len() = 1456
Compiling module...
  2.35s            Module::new (compile)

After:

code.len() = 1456
Compiling module...
  235.85ms         Module::new (compile)

Cargo.toml Outdated Show resolved Hide resolved
@syrusakbary
Copy link
Contributor

This is awesome. We knew using a VecAssembler could be more optimal, but we didn't measure by how much... so great work!
Do you mind to do a PR also upstream @ailisp ? Thanks!

bors bot added a commit to wasmerio/wasmer that referenced this pull request Nov 15, 2021
2681: fix singlepass slow compilation of many function wasm by using dynasm VecAssembler r=syrusakbary a=ailisp

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

We found in certain benchmark (a wasm with 150_000 no-op functions), compilation is slowed down by dynasmrt's mmapand mprotect syscalls, however, those mmap isn't used in wasmer and can be replaced by simpler VecAssembler. In this [bench](near/wasmer#71) it's a 10x speedup in singlepass backend compilation time.

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Bo Yao <[email protected]>
@ailisp
Copy link
Member Author

ailisp commented Nov 16, 2021

@matklad ptal :)

bors bot added a commit to wasmerio/wasmer that referenced this pull request Nov 17, 2021
2681: fix singlepass slow compilation of many function wasm by using dynasm VecAssembler r=ptitSeb a=ailisp

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

We found in certain benchmark (a wasm with 150_000 no-op functions), compilation is slowed down by dynasmrt's mmapand mprotect syscalls, however, those mmap isn't used in wasmer and can be replaced by simpler VecAssembler. In this [bench](near/wasmer#71) it's a 10x speedup in singlepass backend compilation time.

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Bo Yao <[email protected]>
Copy link
Contributor

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and thanks for upstreaming this! Let's hold off pulling this in until the next week -- we are going to branch the release soon, merging after release should give this change more time to bake in, and maybe even update the corresponding costs.

nagisa pushed a commit that referenced this pull request Nov 24, 2021
2681: fix singlepass slow compilation of many function wasm by using dynasm VecAssembler r=ptitSeb a=ailisp

<!--
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

<!--
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

We found in certain benchmark (a wasm with 150_000 no-op functions), compilation is slowed down by dynasmrt's mmapand mprotect syscalls, however, those mmap isn't used in wasmer and can be replaced by simpler VecAssembler. In this [bench](#71) it's a 10x speedup in singlepass backend compilation time.

- [ ] Add a short description of the change to the CHANGELOG.md file

Co-authored-by: Bo Yao <[email protected]>
@nagisa
Copy link
Collaborator

nagisa commented Nov 24, 2021

I went ahead and manually cherry-picked in the change from upstream at 7945c3e, since its been approved and landed there.

@nagisa nagisa closed this Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants