-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make use of CompletionStage#handle instead of whenComplete
#3221
Conversation
@He-Pin Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
1 similar comment
@He-Pin Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@He-Pin Thank you for signing the Contributor License Agreement! |
@He-Pin thank you for the proposal, looks like a good perf improvement. |
@chemicL this should be forwardmerged. Lazy one uses same method as well |
I just noticed #3222 which addresses the issue on |
@chemicL Yes ,I created two PR, one for 3.4.x and one for main, I saw @OlegDokuka did more optimizations of memory usage on the current main branch:) |
@He-Pin second is going to be closed since we use forward merge to keep both branches connected |
But in the second one, you fold the |
jmh:run -i 5 -wi 5 -f1 -t1 .CompletionStageBenchmark. package bench
import org.openjdk.jmh.annotations._
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@State(Scope.Benchmark)
@OutputTimeUnit(TimeUnit.SECONDS)
@BenchmarkMode(Array(Mode.Throughput))
class CompletionStageBenchmark {
val ex = new RuntimeException("ex")
@Benchmark
def benchWhenCompleteFailedSync(): Unit = {
val future = new CompletableFuture[Int]()
future.completeExceptionally(ex)
val latch = new CountDownLatch(1)
future.whenComplete((_, _) => latch.countDown())
latch.await()
}
@Benchmark
def benchWhenCompleteSuccessSync(): Unit = {
val future = new CompletableFuture[Int]()
future.complete(1)
val latch = new CountDownLatch(1)
future.whenComplete((_, _) => latch.countDown())
latch.await()
}
@Benchmark
def benchHandleFailedSync(): Unit = {
val future = new CompletableFuture[Int]()
future.completeExceptionally(ex)
val latch = new CountDownLatch(1)
future.handle((_, _) => latch.countDown())
latch.await()
}
@Benchmark
def benchHandleSuccessSync(): Unit = {
val future = new CompletableFuture[Int]()
future.complete(1)
val latch = new CountDownLatch(1)
future.handle((_, _) => latch.countDown())
latch.await()
}
}
|
whenComplete
.whenComplete
@simonbasle this PR seems to have been merged on a maintenance branch, please ensure the change is merge-forwarded to intermediate maintenance branches and up to |
Which has better performance.
line/armeria#1596