Should I use akka.http.scaladsl.util.FastFuture instead of scala.concurrent.Future?

房东的猫 提交于 2019-12-24 02:25:12

问题


Should I use akka.http.scaladsl.util.FastFuture instead of scala.concurrent.Future?

The comment says :

/**
 * Provides alternative implementations of the basic transformation operations defined on [[scala.concurrent.Future]],
 * which try to avoid scheduling to an [[scala.concurrent.ExecutionContext]] if possible, i.e. if the given future
 * value is already present.
 */

Do I get any performance improvement especially when I need to use Future.apply, Future.successful or Future.failed?

What exactly is the difference between the two implementations?


回答1:


Essentially FastFuture allows to bypass the Future's submission to an ExecutionContext in case the future is already completed (either successfully or not).

So in short, yes, it can give you performance improvements. Whether those will be negligible or substantial, it depends on the application you are developing.

I believe there was a plan to make these improvements part of Scala 2.12, but I never heard of those being concretised.



来源:https://stackoverflow.com/questions/42808593/should-i-use-akka-http-scaladsl-util-fastfuture-instead-of-scala-concurrent-futu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!