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

Adapt backend usage depending on wasm file executed #1004

Merged
merged 1 commit into from
Nov 27, 2019

Conversation

d0iasm
Copy link
Contributor

@d0iasm d0iasm commented Nov 22, 2019

Adapt backend usage depending on wasm file executed in issue #998.
Close #998

Description

Add auto backend into a runtime-core and use it as a default backend.
The auto backend is equivalent to:

  • singlepass if singlepass is enabled and the wasm file size is larger than 10MiB, or singlepass is enable and the target architecture is aarch64.
  • cranelift otherwise.

Copy link
Contributor

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

Despites minor comments, the PR looks good. Great job 👍!

@@ -492,6 +492,20 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
None
};

// Update backend when a backend flag is `auto` or a default value.
Copy link
Contributor

Choose a reason for hiding this comment

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

or a default value

Is it still true? By reading the code, I assume it's when the --backend option is set to auto only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I overlooked the Backend::default(). I updated the return value from Cranelift to Auto in Backend::default(), so this comment should be true.

@@ -492,6 +492,20 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
None
};

// Update backend when a backend flag is `auto` or a default value.
// Use a singlepass if it's enable and the file provided is larger
Copy link
Contributor

Choose a reason for hiding this comment

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

- a singlepass
+ the Singlepass backend

Copy link
Contributor

Choose a reason for hiding this comment

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

- it's enable
+ it's enabled

@@ -492,6 +492,20 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
None
};

// Update backend when a backend flag is `auto` or a default value.
// Use a singlepass if it's enable and the file provided is larger
// than 10MiB (10485760 bytes), or it's enable and the target architecture
Copy link
Contributor

Choose a reason for hiding this comment

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

- it's enable
+ it's enabled

// Update backend when a backend flag is `auto` or a default value.
// Use a singlepass if it's enable and the file provided is larger
// than 10MiB (10485760 bytes), or it's enable and the target architecture
// is aarch64. Otherwise, use a cranelift as a backend.
Copy link
Contributor

Choose a reason for hiding this comment

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

- use a cranelift as a backend
+ use the Cranelift backend

// is aarch64. Otherwise, use a cranelift as a backend.
if options.backend == Backend::Auto {
if Backend::variants().contains(&Backend::Singlepass.to_string())
&& (wasm_binary.len() > 10485760 || cfg!(target_arch = "aarch64"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on my comprehension of #998, when the --backend option is set to auto, we want to use Cranelift by default, or Singlepass if the module is larger than 10MiB; which translates as:

if Backend::variants().containts(&Backend::Singlepass.to_string()) // Singlepass is available
    && wasm_binary.len() > 10485760 // Large module, be a good candidate for Singlepass
{
    options.backend = Backend::Singlepass;
} else {
    options.backend = Backend::Cranelift;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue #998 only mentions the file size, but I heard from @syrusakbary on Slack that the Singlepass backend is used when the target arch is AArch64. Is it better to add about it to the issue #998, or to remove the condition relating to AArch64 for now?

@Hywan
Copy link
Contributor

Hywan commented Nov 22, 2019

@d0iasm Don't forget to update the CHANGELOG.md file too :-).

@Hywan Hywan self-assigned this Nov 22, 2019
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Looks good!

But I do have a style comment: execute_wasm is a very large function. I think it would help keep the code more readable and maintainable if option: Run was not mutable here. If it's mutable, that means that we need to be aware of where it's changing which can be hard to keep track of and increases the mental burden of understanding on an already too-complex function.

I suggest:

  1. use a helper function which takes option: Run as mutable and is called from run or main, which are smaller functions and can be more easily audited. That is: localize the mutability to prevent it from making the other logic more complex.
  2. use an extra variable backend in execute_wasm instead of mutating it (this may not work because we may need to read the field from Run in a sub-function)

@d0iasm
Copy link
Contributor Author

d0iasm commented Nov 25, 2019

@MarkMcCaskey
Thank you for your suggestions! I chose option 1 because option 2 would affect many places since options is used in other functions such as execute_wasi. I added a new function update_backend called from run. I also reverted options: &mut Run to options: &Run in execute_wasm argument.

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Contributor

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

Look s good to me!

@Hywan
Copy link
Contributor

Hywan commented Nov 25, 2019

bors r+

bors bot added a commit that referenced this pull request Nov 25, 2019
1004: Adapt backend usage depending on wasm file executed r=Hywan a=d0iasm

Adapt backend usage depending on wasm file executed in issue #998.
Close #998 

# Description
Add `auto` backend into a runtime-core and use it as a default backend.
The `auto` backend is equivalent to: 
* singlepass if singlepass is enabled and the wasm file size is larger than 10MiB, or singlepass is enable and the target architecture is aarch64.
* cranelift otherwise.


Co-authored-by: Asami Doi <doiasami1219@gmail.com>
Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented Nov 25, 2019

Build failed

@Hywan
Copy link
Contributor

Hywan commented Nov 25, 2019

bors r+

bors bot added a commit that referenced this pull request Nov 25, 2019
1004: Adapt backend usage depending on wasm file executed r=Hywan a=d0iasm

Adapt backend usage depending on wasm file executed in issue #998.
Close #998 

# Description
Add `auto` backend into a runtime-core and use it as a default backend.
The `auto` backend is equivalent to: 
* singlepass if singlepass is enabled and the wasm file size is larger than 10MiB, or singlepass is enable and the target architecture is aarch64.
* cranelift otherwise.


Co-authored-by: Asami Doi <doiasami1219@gmail.com>
Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented Nov 25, 2019

Build failed

@d0iasm
Copy link
Contributor Author

d0iasm commented Nov 27, 2019

bors r+

bors bot added a commit that referenced this pull request Nov 27, 2019
1004: Adapt backend usage depending on wasm file executed r=d0iasm a=d0iasm

Adapt backend usage depending on wasm file executed in issue #998.
Close #998 

# Description
Add `auto` backend into a runtime-core and use it as a default backend.
The `auto` backend is equivalent to: 
* singlepass if singlepass is enabled and the wasm file size is larger than 10MiB, or singlepass is enable and the target architecture is aarch64.
* cranelift otherwise.


Co-authored-by: Asami Doi <doiasami1219@gmail.com>
Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented Nov 27, 2019

Build failed

@d0iasm
Copy link
Contributor Author

d0iasm commented Nov 27, 2019

The test cache::tests::test_file_system_cache_run fails because the default compiler is auto but there is no "real" compiler of auto. So, I reverted Backend::default() to return Backend::Cranelift.

@d0iasm
Copy link
Contributor Author

d0iasm commented Nov 27, 2019

bors try

bors bot added a commit that referenced this pull request Nov 27, 2019
@bors
Copy link
Contributor

bors bot commented Nov 27, 2019

try

Build succeeded

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me! We can add some #[cfg] logic in Backend::default later for aarch64, but this looks good to ship now!

@MarkMcCaskey
Copy link
Contributor

bors r+

bors bot added a commit that referenced this pull request Nov 27, 2019
1004: Adapt backend usage depending on wasm file executed r=MarkMcCaskey a=d0iasm

Adapt backend usage depending on wasm file executed in issue #998.
Close #998 

# Description
Add `auto` backend into a runtime-core and use it as a default backend.
The `auto` backend is equivalent to: 
* singlepass if singlepass is enabled and the wasm file size is larger than 10MiB, or singlepass is enable and the target architecture is aarch64.
* cranelift otherwise.


Co-authored-by: Asami Doi <doiasami1219@gmail.com>
@bors
Copy link
Contributor

bors bot commented Nov 27, 2019

Build succeeded

@bors bors bot merged commit fd0df99 into master Nov 27, 2019
@bors bors bot deleted the feature/autodetect-backend branch November 27, 2019 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature! 📦 lib-cli About wasmer-cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adapt backend usage depending on wasm file executed
3 participants