-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-codegenArea: Code generationArea: Code generationC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
Description
I have a [u8; 4]
and I want to copy an unknown number of bytes from it into a &mut [u8]
. Based on benchmarking, on x86_64 at least it is much slower to call memcpy
than it is to do a byte-by-byte copy. The fastest implementation of this pattern in Rust is this:
if len > 4 {
core::hint::unreachable_unchecked();
}
for i in 0..len {
*dst.get_unchecked_mut(i) = src[i];
}
That just doesn't seem right to me.
Metadata
Metadata
Assignees
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-codegenArea: Code generationArea: Code generationC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.