rust/library/alloc/src
Guillaume Gomez b917753d79
Rollup merge of #120116 - the8472:only-same-alignments, r=cuviper
Remove alignment-changing in-place collect

This removes the alignment-changing in-place collect optimization introduced in #110353
Currently stable users can't benefit from the optimization because GlobaAlloc doesn't support alignment-changing realloc and neither do most posix allocators. So in practice it has a negative impact on performance.

Explanation from https://github.com/rust-lang/rust/issues/120091#issuecomment-1899071681:

> > You mention that in case of alignment mismatch -- when the new alignment is less than the old -- the implementation calls `mremap`.
>
> I was trying to note that this isn't really the case in practice, due to the semantics of Rust's allocator APIs. The only use of the allocator within the `in_place_collect` implementation itself is [a call to `Allocator::shrink()`](db7125f008/library/alloc/src/vec/in_place_collect.rs (L299-L303)), which per its documentation [allows decreasing the required alignment](https://doc.rust-lang.org/1.75.0/core/alloc/trait.Allocator.html). However, in stable Rust, the only available `Allocator` is [`Global`](https://doc.rust-lang.org/1.75.0/alloc/alloc/struct.Global.html), which delegates to the registered `GlobalAlloc`. Since `GlobalAlloc::realloc()` [cannot change the required alignment](https://doc.rust-lang.org/1.75.0/core/alloc/trait.GlobalAlloc.html#method.realloc), the implementation of [`<Global as Allocator>::shrink()`](db7125f008/library/alloc/src/alloc.rs (L280-L321)) must fall back to creating a brand-new allocation, `memcpy`ing the data into it, and freeing the old allocation, whenever the alignment doesn't remain exactly the same.
>
> Therefore, the underlying allocator, provided by libc or some other source, has no opportunity to internally `mremap()` the data when the alignment is changed, since it has no way of knowing that the allocation is the same.
2024-01-20 20:06:35 +01:00
..
alloc run alloc benchmarks in Miri and fix UB 2022-11-07 10:34:04 +01:00
boxed Remove no-longer-needed allow(dead_code) from the standard library 2024-01-18 13:14:42 -05:00
collections Adjust library tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
ffi Update c_str.rs 2023-12-14 19:08:36 -05:00
raw_vec add more niches to rawvec 2023-12-11 23:38:48 +01:00
rc remove redundant imports 2023-12-10 10:56:22 +08:00
slice ignore core, alloc and test tests that require unwinding on panic=abort 2023-06-13 15:53:24 +02:00
sync remove redundant imports 2023-12-10 10:56:22 +08:00
testing Share testing utilities with non-btree test cases 2022-05-02 10:07:50 +02:00
vec Rollup merge of #120116 - the8472:only-same-alignments, r=cuviper 2024-01-20 20:06:35 +01:00
alloc.rs Add proper cfgs 2023-11-28 09:02:34 +08:00
borrow.rs Add more diagnostic items for clippy 2023-10-05 18:21:47 -04:00
boxed.rs Adjust library tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
fmt.rs Closure-consuming helper functions for fmt::Debug helpers 2023-11-10 07:50:11 +09:00
lib.rs mark vec::IntoIter pointers as !nonnull 2024-01-07 03:44:04 +01:00
macros.rs Update doc for alloc::format! and core::concat! 2023-09-06 15:11:21 +02:00
raw_vec.rs chore: remove unnecessary blank line 2024-01-11 09:45:21 +08:00
rc.rs rc: Take *const T in is_dangling 2023-12-30 16:28:00 +09:00
slice.rs Add suggestion for some #[deprecated] items 2023-08-21 12:51:51 +03:00
str.rs [nit] Fix a comment typo. 2023-08-15 14:26:14 -05:00
string.rs Rollup merge of #95967 - CAD97:from-utf16, r=dtolnay 2023-10-11 03:53:16 +03:00
sync.rs Rollup merge of #119434 - taiki-e:rc-is-dangling, r=Mark-Simulacrum 2024-01-03 16:08:25 +01:00
task.rs Updating Wake example to use new 'pin!' macro 2023-04-25 13:50:50 +02:00
tests.rs remove redundant imports 2023-12-10 10:56:22 +08:00