google / moveit

Apache License 2.0
166 stars 18 forks source link

Stack overflow #9

Open Nugine opened 3 years ago

Nugine commented 3 years ago

https://github.com/google/moveit/blob/5f9f8c71ec61179a01d5743982a79566a3b1c1f4/src/alloc_support.rs#L81

https://github.com/rust-lang/rust/issues/63291

Assigning MaybeUninit::::uninit() to a local variable is usually free, even when size_of::() is large. However, passing it for example to Arc::new causes at least one copy (from the stack to the newly allocated heap memory) even though there is no meaningful data.

AFAIK, there is no way to construct Arc<MaybeUninit<T>> and Rc<MaybeUninit<T>> efficiently until feature(new_uninit) is stable.

mcy commented 3 years ago

Known limitation =(. I'll gladly review a patch that introduces a nightly feature and swaps this in for the relevant Emplace implementations.