Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of FastFuture in akka

Tags:

scala

akka

future

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?

like image 295
Saurabh Avatar asked Nov 24 '17 18:11

Saurabh


1 Answers

When an ExecutionContext is used in map calls, that involves extra scheduling cost in scala Futures, while with akka FastFutures 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 FastFutures too as it should use that for scheduling the generated Futures.

It might worth checking Viktor Klang's blog and the discussion related Futures on Scala contributors page.

like image 171
Gábor Bakos Avatar answered Nov 06 '22 15:11

Gábor Bakos