-
Notifications
You must be signed in to change notification settings - Fork 957
Avoid using CompletableFuture.whenCompleteAsync() #1440
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job~!
91de14a
to
bc989d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of performance for free - will take it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
Related: line#1426 Motivation: `CompletableFuture` always creates a new `CompletionException` after it calls the callback registered with `whenCompleteAsync()`, even if there are no dependants and the `CompletionException` will never be used. See https://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java#l870 for more information. Modifications: - Use `CompletableFuture.handleAsync()` instead of `whenCompleteAsync()`. - Miscellaneous: - Avoid using `voidFunction()` which increases the level of indirection Result: - Fixes line#1426 - Better performance master: Benchmark (clientType) Mode Cnt Score Error Units DownstreamSimpleBenchmark.empty NORMAL thrpt 100 52167.567 ± 274.358 ops/s This pull request: Benchmark (clientType) Mode Cnt Score Error Units DownstreamSimpleBenchmark.empty NORMAL thrpt 100 58171.594 ± 365.014 ops/s
bc989d9
to
93df38b
Compare
Codecov Report
@@ Coverage Diff @@
## master #1440 +/- ##
==========================================
- Coverage 72.62% 72.57% -0.06%
==========================================
Files 617 617
Lines 26820 26832 +12
Branches 3245 3245
==========================================
- Hits 19477 19472 -5
- Misses 5636 5655 +19
+ Partials 1707 1705 -2
Continue to review full report at Codecov.
|
Ran the benchmark again today for #1444 and the throughput of this pull request is now around 54,000-56,000. Maybe not as dramatic as initially observed, although it's still quite an improvement. |
Motivation: As we discovered in line#1440, `whenComplete()` is harmful for performance. Modifications: - Use `handle()` instead of `whenComplete()` Result: - Potentially less unnecessary instantiation of `CompletionException`.
Motivation: As we discovered in #1440, `whenComplete()` is harmful for performance. Modifications: - Use `handle()` instead of `whenComplete()` Result: - Potentially less unnecessary instantiation of `CompletionException`.
Related: line#1426 Motivation: `CompletableFuture` always creates a new `CompletionException` after it calls the callback registered with `whenCompleteAsync()`, even if there are no dependants and the `CompletionException` will never be used. See https://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java#l870 for more information. Modifications: - Use `CompletableFuture.handleAsync()` instead of `whenCompleteAsync()`. - Miscellaneous: - Avoid using `voidFunction()` which increases the level of indirection Result: - Fixes line#1426 - Better performance master: Benchmark (clientType) Mode Cnt Score Error Units DownstreamSimpleBenchmark.empty NORMAL thrpt 100 52167.567 ± 274.358 ops/s This pull request: Benchmark (clientType) Mode Cnt Score Error Units DownstreamSimpleBenchmark.empty NORMAL thrpt 100 58171.594 ± 365.014 ops/s
Motivation: As we discovered in line#1440, `whenComplete()` is harmful for performance. Modifications: - Use `handle()` instead of `whenComplete()` Result: - Potentially less unnecessary instantiation of `CompletionException`.
Related: #1426
Motivation:
CompletableFuture
always creates a newCompletionException
after itcalls the callback registered with
whenCompleteAsync()
, even if thereare no dependants and the
CompletionException
will never be used.See https://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java#l870
for more information.
Modifications:
CompletableFuture.handleAsync()
instead ofwhenCompleteAsync()
.voidFunction()
which increases the level of indirectionResult:
master:
This pull request: