Skip to content

ptr::copy_nonoverlapping slower then manual bytewise copy #97022

Open

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

Activity

  1. added
    I-slowIssue: Problems and improvements with respect to performance of generated code.
    on May 13, 2022
  2. saethlin commented on May 14, 2022

    @saethlin
    Member

    Similar to #92993

  3. mati865 commented on May 29, 2022

    @mati865
    Member

    Related to #83785

  4. zeroflaw commented on Sep 7, 2023

    @zeroflaw

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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