-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Lock step loop codegen issue #38175
Comments
This code looks like enough to reproduce in current nightly: pub fn extend_1(v: &mut Vec<u8>, data: &[u8; 16]) {
v.extend(data)
} |
Reduced to not use so much library code (playground link) Replacing fn extend(v: &mut Vec<u8>, input: &[u8]) {
v.reserve(input.len());
unsafe {
let mut dst = v.as_mut_ptr().offset(v.len() as isize);
let mut iter = input.iter().map(|&x| x);
while let Some(elt) = iter.next() {
*dst = elt;
dst = dst.offset(1);
}
let new_len = v.len() + input.len();
v.set_len(new_len);
}
}
#[no_mangle]
pub fn extend_1(v: &mut Vec<u8>, data: &[u8; 16]) {
extend(v, data);
} |
The reduced case above can be fixed like this (look at fn extend(v: &mut Vec<u8>, input: &[u8]) {
v.reserve(input.len());
unsafe {
let dst = v.as_mut_ptr();
let mut i = v.len() as isize;
let mut iter = input.iter().map(|&x| x);
while let Some(elt) = iter.next() {
*dst.offset(i) = elt;
i += 1;
}
let new_len = v.len() + input.len();
v.set_len(new_len);
}
} but this fix does not seem to work to resolve the serialization regression in extend/TrustedLen. |
I extracted what I think is supposed to be the slow and fast version from the playground link above. It looks like this was fixed with rustc 1.20: https://godbolt.org/z/r8vcx64Kx Squinting at the LLVM IR in the gist linked above, it seems like the same pile of 1-byte moves that are emitted by rustc 1.19, but collapsed down by rust 1.20. |
The original issue is the performance regression in #38021 when using the TrustedLen specialization of
Extend<&T> for Vec
.In pseudocode you can describe their difference like this:
A reduced case to demonstrate the issue is https://gist.github.com/bluss/61c32daae1bd31d9d7605983df3ace5f
The text was updated successfully, but these errors were encountered: