Upgrade Monix #4

merged 2 commits into from Jan 27, 2017


None yet

3 participants


We seem to have suffered some performance regressions in 2.1.x due to basically making Monix's Task safer to use, however after a round of improvements (that will be released in the next major version) I have really good results.

Here are the results of my execution using this PR:

[info] Benchmark                   (size)   Mode  Cnt     Score     Error  Units
[info] FlatMap.fs2Apply             10000  thrpt   20   291.459 ±   6.321  ops/s
[info] FlatMap.fs2Delay             10000  thrpt   20  2606.864 ±  26.442  ops/s
[info] FlatMap.fs2Now               10000  thrpt   20  3867.300 ± 541.241  ops/s
[info] FlatMap.futureApply          10000  thrpt   20   212.691 ±   9.508  ops/s
[info] FlatMap.futureSuccessful     10000  thrpt   20   418.736 ±  29.121  ops/s
[info] FlatMap.futureTrampolineEc   10000  thrpt   20   423.647 ±   8.543  ops/s
[info] FlatMap.monixApply           10000  thrpt   20   399.916 ±  15.858  ops/s
[info] FlatMap.monixDelay           10000  thrpt   20  4994.156 ±  40.014  ops/s
[info] FlatMap.monixNow             10000  thrpt   20  6253.182 ±  53.388  ops/s
[info] FlatMap.scalazApply          10000  thrpt   20   188.387 ±   2.989  ops/s
[info] FlatMap.scalazDelay          10000  thrpt   20  1794.680 ±  24.173  ops/s
[info] FlatMap.scalazNow            10000  thrpt   20  2041.300 ± 128.729  ops/s

Some details:

  • Test system is a MacBook Pro with 2,2 GHz Intel Core i7 and 16 GB of RAM
  • I stopped all running apps and services that I could before running these tests
  • I reconfigured the used thread-pool for Monix; and the default execution model is now SynchronousExecution, otherwise it's not an apples to apples comparison in the Delay and the Now tests

So in terms of flatMap behavior, we're still the king of the hill 😜
Btw, I'm trying to make the next Typelevel Summit and Scala Days, hope to meet you there.

Happy New Year ⛄


Wow, just wow... happy new year Alex! Great work you're doing!

+ // Building a Scala 2.11 ForkJoinPool, because the one in
+ // Java 8 / Scala 2.12 has worse performance due to being more fair;
+ // See: https://github.com/monix/monix-forkjoin/
+ val executionContext =
rossabaker Jan 3, 2017 Owner

Since Monix, FS2, and Scalaz-Stream all create a Scheduler or Strategy from an ExecutionContext, I wonder whether it makes sense to extract this out, and then use the same for all three. That would help address the concern in #3.

Whether that should be a fixed thread pool or a fork join pool is a separate question. Both, on all three libraries, could be interesting.

alexandru Jan 3, 2017 Contributor

Basically the performance of the thread-pool dominates the Task.apply test, so yes it makes sense to use it for all 3.

You'll actually see the advantage of Monix in that apply test decrease, because ForkJoinPool has a much more aggressive behavior than Java's standard ThreadPoolExecutor, coupled with Monix's logic in Task.apply that's meant for safety: basically Monix's Task executes an extra run-loop (flatMap) iteration on Task.fork in order to prevent stack overflows, so it ends up doing more work than Scalaz at least (actually the Scalaz Task has a lot of stack-unsafe methods, including mapBoth, which was a WTF moment).

This was a long way of saying that yes, it would be more fair to have the same thread-pool used by all 3 because it matters; and I'm saying this even though Monix right now has an unfair advantage in that test.



Is there a rough timeline for 2.2.0? I like to make the runs repeatable, so we'll either want to wait to republish until that's released, or do a source dependency to HEAD like we've done for fs2 before tagging results.


2.2.0 final release has a new type I'm working on, so it might be long before I release it, however I plan to release a milestone 2.2.0-M1 for previewing.

I don't know how to do a HEAD dependency, but I'm going to publish 2.2.0-M1 ~ tomorrow.


I updated the PR with 2.2.0-M1.


Been busy, but I see there's a 2.2.1 out there. I'll bump up to that and try to get another run this weekend.

@rossabaker rossabaker merged commit 3fbe5e1 into rossabaker:master Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment