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

Heap allocation of Arc not optimized out compared to Rc #97751

Open
veber-alex opened this issue Jun 5, 2022 · 1 comment
Open

Heap allocation of Arc not optimized out compared to Rc #97751

veber-alex opened this issue Jun 5, 2022 · 1 comment
Labels
C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@veber-alex
Copy link
Contributor

veber-alex commented Jun 5, 2022

I tried this code:

use std::rc::Rc;
use std::sync::Arc;

struct Data {
    a: u64,
    b: u64,
}

fn add_numbers(p: &Data) -> u64 {
    p.a + p.b
}

pub fn add_two_numbers_arc(a: u64, b: u64) -> u64 {
    let x = Arc::new(Data { a, b });
    add_numbers(&x)
}

pub fn add_two_numbers_rc(a: u64, b: u64) -> u64 {
    let x = Rc::new(Data { a, b });
    add_numbers(&x)
}

godbolt link

I expected to see this happen: The heap allocation of both the Rc and the Arc should be optimized out.

Instead, this happened: Only Rc got the optimization.

@veber-alex veber-alex added the C-bug Category: This is a bug. label Jun 5, 2022
@veber-alex
Copy link
Contributor Author

@rustbot modify labels +I-slow

@rustbot rustbot added the I-slow Issue: Problems and improvements with respect to performance of generated code. label Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

2 participants