diff options
| author | bors <bors@rust-lang.org> | 2021-02-11 04:40:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-11 04:40:57 +0000 |
| commit | 1efd8049837aec86f21da1486e8a459a7efd7806 (patch) | |
| tree | 8f8c3ebfed31260b12470da6431a96231e39f7aa /compiler/rustc_codegen_llvm/src/llvm_util.rs | |
| parent | 9ce7268bcfc17265bd05e4c08713d170d39618ad (diff) | |
| parent | 2a11c57fb04d68c261dc14f6cf1aa3f8f14f0a2e (diff) | |
| download | rust-1efd8049837aec86f21da1486e8a459a7efd7806.tar.gz rust-1efd8049837aec86f21da1486e8a459a7efd7806.zip | |
Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-se
Optimize Vec::retain Use `copy_non_overlapping` instead of `swap` to reduce memory writes, like what we've done in #44355 and `String::retain`. #48065 already tried to do this optimization but it is reverted in #67300 due to bad codegen of `DrainFilter::drop`. This PR re-implement the drop-then-move approach. I did a [benchmark](https://gist.github.com/oxalica/3360eec9376f22533fcecff02798b698) on small-no-drop, small-need-drop, large-no-drop elements with different predicate functions. It turns out that the new implementation is >20% faster in average for almost all cases. Only 2/24 cases are slower by 3% and 5%. See the link above for more detail. I think regression in may-panic cases is due to drop-guard preventing some optimization. If it's permitted to leak elements when predicate function of element's `drop` panic, the new implementation should be almost always faster than current one. I'm not sure if we should leak on panic, since there is indeed an issue (#52267) complains about it before.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm_util.rs')
0 files changed, 0 insertions, 0 deletions
