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

Rust Counter Optimization #1

Open
bjfish opened this issue Aug 21, 2018 · 8 comments
Open

Rust Counter Optimization #1

bjfish opened this issue Aug 21, 2018 · 8 comments

Comments

@bjfish
Copy link

bjfish commented Aug 21, 2018

From the article: https://blog.sqreen.io/webassembly-performance/

I compiled the rust example for the counter and saw the count function compiles to this wasm:

  (func $count (type $t0) (param $p0 i32)
    i32.const 0
    i32.const 0
    i32.store offset=1048640)

So, I believe the numerical operations you had intended on comparing in this benchmark may have all been optimized away by aggressive compiler optimizations?

@bjfish bjfish changed the title Counter Optimization Rust Counter Optimization Aug 21, 2018
@vdeturckheim
Copy link
Contributor

@bjfish make sense! Thanks for pointing that out. What Algorithm would you suggest for a better teste here?

@MaxGraey
Copy link

Just use this:

#[allow(non_snake_case)]
#[wasm_bindgen]
pub fn count(max: i32) -> i32 {
    let mut res = 0;
    for i in 0..max {
        res = res + 1;
    };
    res
}

@vdeturckheim
Copy link
Contributor

Thanks @MaxGraey !

@MaxGraey
Copy link

MaxGraey commented Aug 23, 2018

Oh, no! It still use some aggressive optimization. Just sec

@MaxGraey
Copy link

MaxGraey commented Aug 23, 2018

it seems in rust you should use random value for increment. This affect for run as well.

@MaxGraey
Copy link

Or just skip this bench sample as trivial and very syntactic.

@ballercat
Copy link

At this point, you might as well write it in plain wast.

@vdeturckheim
Copy link
Contributor

@ballercat that's another possibility, I don't have any bandwidth on this topic until mid-September, also, the latest updates in V8 might give us some new results.

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

No branches or pull requests

4 participants