Skip to content

Box::new() performance regression between 1.18 and 1.19 beta #42562

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

Closed
rom1v opened this issue Jun 9, 2017 · 6 comments
Closed

Box::new() performance regression between 1.18 and 1.19 beta #42562

rom1v opened this issue Jun 9, 2017 · 6 comments
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@rom1v
Copy link

rom1v commented Jun 9, 2017

It seems there is a performance regression related to Box::new() between 1.18 and 1.19 beta.

use std::time::Instant;

fn main() {
    let timer = Instant::now();
    for _ in 0..100000 {
        Box::new([0; 1000]);
    }
    println!("{:?}", timer.elapsed());
}

In Release/Stable:

rustc 1.18.0 (03fc9d622 2017-06-06)

Duration { secs: 0, nanos: 107624 }

In Release/Beta, it's ~200× slower:

rustc 1.19.0-beta.1 (a87984118 2017-06-06)

Duration { secs: 0, nanos: 22355940 }

https://is.gd/AaDx3A

@crumblingstatue
Copy link
Contributor

I tested on nightly, it's about 140 times slower than 1.18 stable on my system.

@jonas-schievink
Copy link
Contributor

You're not measuring Box::new, you're measuring the compiler's ability to remove unnecessary allocations. For some reason 1.19+ isn't able to eliminate the allocations, while 1.18 is.

@wesleywiser
Copy link
Member

I think this is related #24194 (comment)

@jonas-schievink
Copy link
Contributor

Fix is #42410

@sanxiyn sanxiyn added the I-slow Issue: Problems and improvements with respect to performance of generated code. label Jun 9, 2017
@joshlf
Copy link
Contributor

joshlf commented Jun 9, 2017

You're not measuring Box::new, you're measuring the compiler's ability to remove unnecessary allocations. For some reason 1.19+ isn't able to eliminate the allocations, while 1.18 is.

You could use test::black_box to prevent this optimization to make sure that that's really the issue.

@nagisa
Copy link
Member

nagisa commented Jun 9, 2017

Closing as a duplicate of #24194

@nagisa nagisa closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

7 participants