Skip to content

Commit c583068

Browse files
authored
perf: change RawVec grow_one from #[inline(never)] to #[inline]
I noticed that this was not inlined when trying to `push` and probably the reason why the compiler lose the information about the capacity (fixes #82801) BTW The original PR that added it (#91352) wrote: > [...] I tried lots of minor variations on this, e.g. different inlining attributes. This was the best one I could find. [...] I never contributed to Rust so I did not know how to test that it actually fixes the problem, but I'm fairly certain it is. Consider the very basic example (Godbolt rustc 1.90.0 `-C opt-level=3 -C target-feature=+avx2 -C codegen-units=1`) ```rust #[no_mangle] fn extend_offsets(offsets: &[usize]) -> Vec::<usize> { let mut intermediate = Vec::<usize>::with_capacity(offsets.len()); for &offset in offsets { intermediate.push(offset) } intermediate } ``` it does not inline `grow_one` which make it not use SIMD. If however we are using [`push_within_capacity`](#100486): ```rust #![feature(vec_push_within_capacity)] #[no_mangle] fn extend_offsets(offsets: &[usize]) -> Vec::<usize> { let mut intermediate = Vec::<usize>::with_capacity(offsets.len()); for &offset in offsets { intermediate.push_within_capacity(offset).unwrap() } intermediate } ``` it will use SIMD
1 parent 9f2ef0f commit c583068

File tree

1 file changed

+1
-1
lines changed
  • library/alloc/src/raw_vec

1 file changed

+1
-1
lines changed

library/alloc/src/raw_vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl<T, A: Allocator> RawVec<T, A> {
334334
/// A specialized version of `self.reserve(len, 1)` which requires the
335335
/// caller to ensure `len == self.capacity()`.
336336
#[cfg(not(no_global_oom_handling))]
337-
#[inline(never)]
337+
#[inline]
338338
#[track_caller]
339339
pub(crate) fn grow_one(&mut self) {
340340
self.inner.grow_one(T::LAYOUT)

0 commit comments

Comments
 (0)