-
Notifications
You must be signed in to change notification settings - Fork 824
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
Conversation
There was a problem hiding this 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 👍!
src/bin/wasmer.rs
Outdated
@@ -492,6 +492,20 @@ fn execute_wasm(options: &Run) -> Result<(), String> { | |||
None | |||
}; | |||
|
|||
// Update backend when a backend flag is `auto` or a default value. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/bin/wasmer.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/bin/wasmer.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
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
src/bin/wasmer.rs
Outdated
// 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. |
There was a problem hiding this comment.
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
src/bin/wasmer.rs
Outdated
// 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")) |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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?
@d0iasm Don't forget to update the |
There was a problem hiding this 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:
- use a helper function which takes
option: Run
as mutable and is called fromrun
ormain
, 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. - use an extra variable
backend
inexecute_wasm
instead of mutating it (this may not work because we may need to read the field fromRun
in a sub-function)
fadc573
to
5f2854c
Compare
@MarkMcCaskey |
There was a problem hiding this 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!
There was a problem hiding this 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!
bors r+ |
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 <[email protected]> Co-authored-by: Ivan Enderlin <[email protected]>
Build failed |
bors r+ |
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 <[email protected]> Co-authored-by: Ivan Enderlin <[email protected]>
Build failed |
bors r+ |
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 <[email protected]> Co-authored-by: Ivan Enderlin <[email protected]>
Build failed |
9d958d7
to
757017b
Compare
757017b
to
fd0df99
Compare
The test |
bors try |
tryBuild succeeded |
There was a problem hiding this 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!
bors r+ |
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 <[email protected]>
Build succeeded |
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: