Skip to content

Missed loop optimization for &Vec argument in .zip() #36920

Description

@bluss

This is a case where two almost identical functions have very different performance, because the slice version is autovectorized and the vector version is not. Note that specialization is involved, but both cases use exactly the same code path, for the slice iterator.

#![crate_type="lib"]

#[no_mangle]
pub fn dot_s(xs: &[u32], ys: &[u32]) -> u32 {
    let mut s = 0;
    for (x, y) in xs.iter().zip(ys) {
        s += x * y;
    }
    s
}

#[no_mangle]
pub fn dot_v(xs: &Vec<u32>, ys: &Vec<u32>) -> u32 {
    let mut s = 0;
    for (x, y) in xs.iter().zip(ys) {
        s += x * y;
    }
    s
}

Using rustc 1.14.0-nightly (289f3a4 2016-09-29)

Note: The Vec vs slice difference is sometimes visible in actual inline use of .zip in code, depending on exact context.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions