dashmap
dashmap copied to clipboard
Feature request: fallible allocations
Now that HashMap has fallible allocations (https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html#fallible-allocation), I would love to see this come to DashMap as well. Right now, using DashMap in low memory situations can result in the entire process aborting.
Is this on the team's radar?
This isn't something I have planned to implement. DashMap is somewhat in maintainance mode from my side and I lack the time to actively implement new features and the crate is at a point where most are happy with it. That said I would be happy to review + help with + release a patch for this if someone else wants to write some code.
Decided to give this a go.
Two things worth discussing:
- Should we reserve space for
additional
entries in each shard, resulting in at leastself.shards.len() * additional
space allocated, or something likeceiling(additional / self.shards.len())
in each shard, which might give users unexpected behavior if too many newly inserted keys end up in the same shard. - It would be best to return
std::collections::TryReserveError
, but it's impossible to maphashbrown::TryReserveError
intostd::collections::TryReserveError
as standard libraryHashMap
does beforeTryReserveErrrorKind
stabilizes, maybe we should wait with this PR until then?