Skip to content

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

Open
@veber-alex

Description

@veber-alex

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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