Skip to content

manual_memcpy may be harmful to performance in some cases #9832

@shssoichiro

Description

@shssoichiro

Summary

I was profiling an application this evening and discovered that a large portion of the time is being spent calling out to libc's memcpy, which is a result of using either copy_from_slice or copy_from_nonoverlapping. This is a best practice suggested by clippy's manual_memcpy lint. However, in the cases of small copies, this can actually harm performance. In my current case, the copies are all 128 bytes or less, and so there is a significant improvement in performance by letting the compiler generate the move instructions itself, rather than calling out to libc.

See rust-av/ssimulacra2@131a6c7 for example

Reproducer

No response

Version

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions