Skip to content

ptr::copy_nonoverlapping slower then manual bytewise copy #97022

Open
@tower120

Description

@tower120

The following code:

#[inline]
unsafe fn copy_bytes(src: *const u8, dst: *mut u8, count: usize){
    for i in 0..count{
        *dst.add(i) = *src.add(i);
    }
}

is significantly FASTER then ptr::copy_nonoverlapping, for small counts, and cases where count is not known at compile time. (2-3 times for 8 byte copy).

People suggest that this happens, because compiler does not inline copy_nonoverlapping code:
https://users.rust-lang.org/t/ptr-copy-nonoverlapping-slower-then-manual-per-byte-copy/75588/2?u=tower120

I'm not sure if this is actually a bug though...

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