Open jimblandy opened 4 days ago
I was thinking it might be better to keep them in insertion order since I would imagine older items to be more likely to be dropped first (leading to less branch mispredictions in the loop) but I don't know how much better that is compared to not using the free list and not having as many branches in the first place.
I opened https://github.com/gfx-rs/wgpu/pull/6587.
Actually, the current implementation doesn't have that property either once the free list starts to be used, I think we can just go with https://github.com/gfx-rs/wgpu/pull/6587.
wgpu_core::weak_vec::WeakVec
maintains a freelist, but it's not important that elements stay at their original indices, so it should be possible to usestd::vec::Vec::swap_remove
to remove broken weak references, thus keeping all live references contiguous at the start of the vector, making the freelist unnecessary.