akka中的FastFuture有什么用
What is the use of FastFuture in akka
akka中Fastfuture有什么用,从文档看不清楚:
Provides alternative implementations of the basic transformation operations defined on Future, which try to avoid scheduling to an ExecutionContext if possible, i.e. if the given future value is already present.
它与 Future 有何不同,有人可以举例说明它在什么情况下使用以及它在性能或任何其他方面提供什么好处吗?
当在 map
调用中使用 ExecutionContext
时,这涉及 scala Future
s 中的额外调度成本,而使用 akka FastFuture
s 它可以在同一个线程避免潜在的上下文切换并可能导致非常短的任务(如简单的数字运算)的缓存未命中。所以对于快速 map
操作 FastFuture
应该更快。
请注意,flatMap
通常也需要 FastFuture
中的 ExecutionContext
,因为它应该使用它来安排生成的 Future
。
可能值得检查 Viktor Klang's blog and the discussion related Futures on Scala contributors page。
akka中Fastfuture有什么用,从文档看不清楚:
Provides alternative implementations of the basic transformation operations defined on Future, which try to avoid scheduling to an ExecutionContext if possible, i.e. if the given future value is already present.
它与 Future 有何不同,有人可以举例说明它在什么情况下使用以及它在性能或任何其他方面提供什么好处吗?
当在 map
调用中使用 ExecutionContext
时,这涉及 scala Future
s 中的额外调度成本,而使用 akka FastFuture
s 它可以在同一个线程避免潜在的上下文切换并可能导致非常短的任务(如简单的数字运算)的缓存未命中。所以对于快速 map
操作 FastFuture
应该更快。
请注意,flatMap
通常也需要 FastFuture
中的 ExecutionContext
,因为它应该使用它来安排生成的 Future
。
可能值得检查 Viktor Klang's blog and the discussion related Futures on Scala contributors page。