Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StateT Performance Regression #2220

Closed
fosskers opened this issue Apr 5, 2018 · 3 comments
Closed

StateT Performance Regression #2220

fosskers opened this issue Apr 5, 2018 · 3 comments

Comments

@fosskers
Copy link
Contributor

fosskers commented Apr 5, 2018

Between 1.0.0 and 1.1.0 (and previously between 0.9 and 1.0.0), StateT has suffered a performance regression. I discovered this when updating versions for scalaz-and-cats.

For:

  type EitherStr[T] = EitherT[Eval, String, T]
  type StEtr[T] = StateT[EitherStr, Int, T]

  def countdownT: StEtr[Unit] = StateT.get[EitherStr, Int].flatMap({ n =>
    if (n <= 0) MonadError[StEtr, String].raiseError("crap")
    else StateT.set[EitherStr, Int](n - 1) *> countdownT
  })

  def runCountDownT: Either[String, (Int, Unit)] = countdownT.run(10000).value.value

we see this runtime drop from 8,920,953 ns to 9,744,808 ns. This is after a 2x slowdown between 0.9 and 1.0.0 which @iravid said had something to do with IndexedStateT. This 9.7 million ns number is around twice as slow as the equivalent ScalaZ, and 5 orders of magnitude slower than Haskell.

@kailuowang
Copy link
Contributor

Thanks for reporting this. It's probably introduced in this PR #2187 which improves the stack safety of StateT.
A very interesting alternative solution might be @iravid 's FreeState, which seems to be 1 order of magnitude faster.

@fosskers
Copy link
Contributor Author

fosskers commented Apr 5, 2018

Can't really get mad about a regression if it's for safety/correctness eh? Cool, hopefully FreeState turns out.

@johnynek
Copy link
Contributor

johnynek commented Apr 5, 2018

We did actually know it was slightly slower, but we made the trade off. It would be very interesting to see if we could recover some of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants