by stevoski · 11y ago · 0 comments
Now...my negative view on using Futures as per the examples in the guide:
Futures (and concurrency in general) make your code much harder to reason about, and much harder to debug. Sequential code running in one thread makes life much easier for the developer.
Faced with the problem presented in the guide (3 method calls total 400 ms), I'd try hard to optimise the methods. Once I've squeezed every potential performance gain out of the sequential method, I'd then investigate caching. Finally, if I still had significant performance problems would I then look at concurrency.
You do have to make sure you're being careful what you pass into your futures--perhaps using immutable objects or defensive copies. It's not trivial, but it's not horrible either.
[1] Yeah, I know there are cases where people use separate processes each running single-threaded, but c'mon.
The example should be considered IO code, which is hard to speed up as you're limited by the other side, not your code. Also I'd say it's much faster in real production environments but you have more calls than three to backend services. I will try to make the calling of backend services clearer in the guide, thanks.