Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized future combinators #17

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

iconara
Copy link
Owner

@iconara iconara commented Oct 31, 2014

When the receiving future is completed many of the combinator methods can be optimized to avoid creating intermediate futures.

This is a work in progress, it basically doubles the size of complexity of the methods.

@iconara iconara force-pushed the optimize_future_combinators branch from b08adea to 84cb1c1 Compare October 31, 2014 16:42
@iconara iconara changed the title Optimize future combinators Optimized future combinators Oct 31, 2014
iconara and others added 16 commits December 12, 2014 07:15
Early return has a cost in JRuby, not big but still a cost.
Wait only for one future at a time. Once the first future has completed, wait for the next one, and so on (short-circuiting when the first fails).

Since we have to wait for them all anyway it doesn’t really matter if we wait for all of them at the same time, or one by one. Once the first future has completed it’s likely that many of the other have also completed, and calling their #on_complete will be cheaper.
Moving them to CompletableFuture allows much more compact expression of
the combinators.
This significantly cuts the implementation size by and should not
introduce too much function call overhead.
Out of the combinators, this is the only case that does not rely on
pre-existing futures, auto detection, or rescuing errors, so the extra
verbosity seems like a reasonable trade-off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants