dashmap icon indicating copy to clipboard operation
dashmap copied to clipboard

Feature request: fallible allocations

Open tomkludy opened this issue 2 years ago • 2 comments

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?

tomkludy avatar Jan 04 '22 23:01 tomkludy

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.

xacrimon avatar Feb 06 '22 15:02 xacrimon

Decided to give this a go.

Two things worth discussing:

  • Should we reserve space for additional entries in each shard, resulting in at least self.shards.len() * additional space allocated, or something like ceiling(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 map hashbrown::TryReserveError into std::collections::TryReserveError as standard library HashMap does before TryReserveErrrorKind stabilizes, maybe we should wait with this PR until then?

tomkarw avatar Jul 17 '22 21:07 tomkarw