3 ms·
Reading the godbolt it looks like for the push loop llvm is unable to remove the `grow_one` capacity check after every push. Becaue of this the Vec could possib
by ironhaven 2y ago
Reading the godbolt it looks like for the push loop llvm is unable to remove the `grow_one` capacity check after every push. Becaue of this the Vec could possibly reallocate after every push meaning it can't auto vectorize.
- mastax 2y agoIt's a little bit surprising to me that LLVM can't eliminate the grow_one check. It looks like there's a test ensure it's not needed in the easier case of vec.push(vec.pop()) [0]. With the iterator the optimization is handled in the standard library using specialization and TrustedLen[1]. [0]: https://github.com/rust-lang/rust/blob/master/tests/codegen/vec_pop_push_noop.rs#L8 https://github.com/rust-lang/rust/blob/master/tests/codegen/... [1]: https://github.com/rust-lang/rust/blob/d4025ee454169fbd22f5773f54348310ab6a47bb/library/alloc/src/vec/mod.rs#L3543 https://github.com/rust-lang/rust/blob/d4025ee454169fbd22f57...