cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

[Performance] Implement IO `redeem()` and `redeemWith()` without Either allocation ?

Open ronanM opened this issue 3 years ago • 1 comments

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))

ronanM avatar Sep 17 '22 17:09 ronanM

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!

djspiewak avatar Sep 19 '22 07:09 djspiewak

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.

djspiewak avatar Oct 29 '22 19:10 djspiewak