Skip to content

Optimise FutureConverters.toScala #89

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

Closed
wants to merge 2 commits into from
Closed

Conversation

t3hnar
Copy link

@t3hnar t3hnar commented Jun 2, 2017

Optimise FutureConverters.toScala for case when CompletionStage backed by CompletableFuture

Optimise `FutureConverters.toScala` for case when `CompletionStage` backed by `CompletableFuture`
@SethTisue
Copy link
Member

@t3hnar I'm sorry, but this seems to have fallen through the cracks. now it needs a rebase, because of merge conflicts in the imports

@t3hnar
Copy link
Author

t3hnar commented Apr 25, 2018

@SethTisue done

@SethTisue
Copy link
Member

the compilation failures are 2.13-only and unrelated to this PR, see #97

@SethTisue
Copy link
Member

now we need a reviewer, maybe @retronym?

@SethTisue SethTisue requested a review from retronym April 25, 2018 12:05
@SethTisue
Copy link
Member

review by @viktorklang?

@@ -78,6 +79,8 @@ object FutureConverters {
def toScala[T](cs: CompletionStage[T]): Future[T] = {
cs match {
case cf: CF[T] => cf.wrapped
case cf: CompletableFuture[T] if cf.isDone =>
Future fromTry Try(cf.get()).recoverWith { case e: ExecutionException => Failure(e.getCause) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this code it is not clear to me that this is in fact an optimization. Is there any benchmark performed that shows what improvement this change leads to?

Copy link
Author

@t3hnar t3hnar Feb 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viktorklang Might be I'm missing something, but I believe that optimised version works faster because of removal of possible context switch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t3hnar I suspect this to be slower: there will be one allocation for the thunk to Try.apply, then another thunk for the recoverWith function. For the other code it will be a single allocation of the P.

@viktorklang
Copy link

viktorklang commented Feb 16, 2019 via email

@t3hnar
Copy link
Author

t3hnar commented Feb 16, 2019

@viktorklang there is no benchmark, just a blind believe, so feel free to reject this pr.

@SethTisue SethTisue closed this Feb 20, 2019
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.

3 participants