Issues with Pool, comparison with alternatives
I have used thunderdome in a previous project. I think there's value in comparing Pool to existing gen arena crates and then either splitting Pool into a separate crate for others to use or replacing it with one of the existing alternatives.
Thunderdome has a comparison table in its readme, the size_of::<Option<Index>>() comparison looks interesting for performance, i don't think Pool uses this optimization.
Pool uses typed Handles, which i consider greatly superior to untyped. Thunderdome and other gen arena crates often use untyped handles, some have typed forks.
Over time i'd like to create a project that compares gen arenas both by features and by performance (there's a similar project for ECS). A first step towards this would be splitting Pool into a separate crate so it can be evaluated more easily.
Some issues i noticed with Pool:
- [ ] Using
asfor casting. I consider theaskeyword problematic because it can silently truncate. There are infallible alternatives for widening conversions such asusize::from. Narrowing conversions are fallible and should either panic or return Option, not silently fail and corrupt data.- [ ] Some methods should probably use
u32instead ofusizesince internally we're limited byu32anyway.
- [ ] Some methods should probably use
- [ ] Using unchecked arithmetic. Thunderdome checks for underflow and overflow everywhere, not sure about others. There should be tests for what happens if allocating more objects than u32 can handle.
- [x] No way to insert at a specific position. I thought
replacewould work if i manually construct a handle but that doesn't seem like it. Inserting at given positions can be useful for syncing game state in multiplayer games. - [ ] Missing docs.
@martin-t Aren't these issues were fixed already?
Most of it. There are still a few as casts and some unchecked arithmetic because we weren't sure properly fixing those wouldn't hurt perf. I wanted to split off Pool into a separate crate and setup benchmarking together with other gen arena crates but realistically i won't have time to do that any time soon.
Similarly, there are still some missing docs but for the methods it's mostly obvious what they do. Some methods could use clarification, e.g. handle_from_index whether it panics or what generation it returns when the index is invalid.
I guess this could be marked as either won't fix or enhancement if anyone wants to take a stab at it - might be a good first contribution.