Skip to content

Using retain() on a vector a lot slower in version 1.38.0 than 1.36.0 #65970

Closed
@Miguel-c-s

Description

@Miguel-c-s

I posted this on stackoverflow.

What happens is that when using retain over a vector, it seems to be a lot slower in version 1.38.0.
host is: x86_64-unknown-linux-gpu (according to rustc--version --verbose) and LLVM version is 8.0.

I'm using ubuntu 19.04.

As I wrote on SO, I tried:

use std::time::Instant;
fn main() {
    let start = Instant::now();
    let mut my_vec:Vec<u32>;
    for _ in 0..100_000{
        my_vec = (0..10_000).collect();
        my_vec.retain(|&x| x < 9000);
        my_vec.retain(|&x| x < 8000);
        my_vec.retain(|&x| x < 7000);
        my_vec.retain(|&x| x < 6000);
        my_vec.retain(|&x| x < 5000);
        my_vec.retain(|&x| (x < 5) & (x > 2));
    }
    let duration = start.elapsed();
    println!("Program took: {:?}", duration);
}

And changed between versions with rustup default 1.36.0 and rustup default stable, having updated rust before with rustup update.
p.s.: From my complete program I also noticed that version 1.38.0 was still a little bit slower without using retain(). But the difference was minimal (~5%) and hard to come up with another culprit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-collectionsArea: `std::collections`C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions