cats-effect
cats-effect copied to clipboard
[Performance] Implement IO `redeem()` and `redeemWith()` without Either allocation ?
Implement IO redeem() and redeemWith() "directly" without Either allocation (via attempt).
Actual:
def redeem[B](recover: Throwable => B, map: A => B): IO[B] =
attempt.map(_.fold(recover, map))
This definitely seems worth doing! I vaguely remember us looking at this a while back though and discovering the attempt implementation was actually the fastest route, but it was like two years ago. We already have RedeemBenchmark, so this should be a relatively straightforward experiment!
This was a cool idea! It looks like it doesn't make a huge difference though, and the impact on other operations is meaningful enough that it isn't worth it.