Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeakVec should consider using Vec::swap_remove instead of a freelist #6580

Open
jimblandy opened this issue Nov 21, 2024 · 2 comments · May be fixed by #6587
Open

WeakVec should consider using Vec::swap_remove instead of a freelist #6580

jimblandy opened this issue Nov 21, 2024 · 2 comments · May be fixed by #6587
Labels
good first issue Good for newcomers kind: refactor Making existing function faster or nicer

Comments

@jimblandy
Copy link
Member

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 use std::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.

@jimblandy jimblandy added kind: refactor Making existing function faster or nicer good first issue Good for newcomers labels Nov 21, 2024
@teoxoy teoxoy linked a pull request Nov 22, 2024 that will close this issue
@teoxoy
Copy link
Member

teoxoy commented Nov 22, 2024

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 #6587.

@teoxoy
Copy link
Member

teoxoy commented Nov 22, 2024

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 #6587.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind: refactor Making existing function faster or nicer
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

2 participants