Skip to content

Commit

Permalink
Inline the CompletionStage and JDK Future implementation into Default…
Browse files Browse the repository at this point in the history
…Promise (#12542)


Motivation:
If we are going to remove the blocking methods from the Netty Future interface, then converting these futures to JDK futures is going to be a lot more common.
The implement these interfaces, we are also going to need access to some underlying blocking primitives, which are exactly the blocking methods that we wish to remove from the public interfaces, and so we'll no longer be able to implement CompletionStage and JDK Future in terms of the Netty Future interface.
As it happens, DefaultPromise already always created and cached a DefaultFutureCompletionStage object, so inlining the implementation removes the allocation and object storage overhead.

Modification:
Move all of the DefaultFutureCompletionStage implementation into DefaultPromise, and adjust the code to avoid the delegation indirection.

Result:
We can now get CompletionStage and JDK Futures from a Netty Future without any allocation.
And even when we don't use those, our Promise and Future implementation is now lighter weight.
  • Loading branch information
chrisvest committed Jul 1, 2022
1 parent 977faa8 commit 9f955c8
Show file tree
Hide file tree
Showing 9 changed files with 1,641 additions and 1,703 deletions.
Expand Up @@ -385,6 +385,16 @@ public V get(long timeout, TimeUnit unit) throws InterruptedException, Execution
return future.get(timeout, unit);
}

@Override
public FutureCompletionStage<V> asStage() {
return future.asStage();
}

@Override
public java.util.concurrent.Future<V> asJdkFuture() {
return future.asJdkFuture();
}

@Override
public int compareTo(RunnableScheduledFuture<?> o) {
return future.compareTo(o);
Expand Down

0 comments on commit 9f955c8

Please sign in to comment.