Skip to content

ptr::copy_nonoverlapping slower then manual bytewise copy #97022

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
tower120 opened this issue May 13, 2022 · 3 comments
Open

ptr::copy_nonoverlapping slower then manual bytewise copy #97022

tower120 opened this issue May 13, 2022 · 3 comments
Labels
C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@tower120
Copy link

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...

@tower120 tower120 added the C-bug Category: This is a bug. label May 13, 2022
@the8472 the8472 added the I-slow Issue: Problems and improvements with respect to performance of generated code. label May 13, 2022
@saethlin
Copy link
Member

Similar to #92993

@mati865
Copy link
Member

mati865 commented May 29, 2022

Related to #83785

@zeroflaw
Copy link

zeroflaw commented Sep 7, 2023

fyi, this now compiles down to the same assembly as copy_nonoverlapping.

# for free to join this conversation on GitHub. Already have an account? # 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

5 participants