What is the use of Fastfuture in akka, not clear from the documentation:
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.
How is it different from Future, Can someone explain with an example in what cases this to be used and what benefit does it provide in terms of performance or any other aspects?
When an ExecutionContext
is used in map
calls, that involves extra scheduling cost in scala Future
s, while with akka FastFuture
s it can perform map in the same thread avoiding potential context switch and potentially causing cache misses for very short tasks (like simple number crunching). So for fast map
operations FastFuture
should be faster.
Please note that flatMap
usually requires an ExecutionContext
in FastFuture
s too as it should use that for scheduling the generated Future
s.
It might worth checking Viktor Klang's blog and the discussion related Futures on Scala contributors page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With