typelevel / cats-effect

The pure asynchronous runtime for Scala
https://typelevel.org/cats-effect/
Apache License 2.0
2.03k stars 520 forks source link

Default constructor for `MapRef` #4136

Open armanbilge opened 1 month ago

armanbilge commented 1 month ago

We currently have many MapRef implementations, based on Ref[Map], sharding, ConcurrentHashMap, etc. We should have an apply constructor that chooses a reasonable default implementation, probably ConcurrentHashMap.

yisraelU commented 1 month ago

@armanbilge I'd like to pick this up

armanbilge commented 1 month ago

@BalmungSan raised a good point that this default constructor should only require a Concurrent constraint. We can pattern-match for Async to use ConcurrentHashMap implementation, otherwise maybe we can fallback to the sharded Ref[Map] with the number of shards determined by the number of processors.

Jasper-M commented 1 month ago

While we're at it, a nicer API for defaultedMapRef would also be welcome. E.g. a constructor that directly takes a default value, or an instance method on trait MapRef. MapRefOptionOps is probably a good place for it too.

armanbilge commented 1 month ago

MapRefOptionOps is probably a good place for it too.

Yes, I think this would be my vote. I think should be easy to chain with the constructor as well so we won't need a separate constructor?