Closed cchacin closed 7 years ago
@@ master #49 diff @@
===================================
Files 4 4
Lines 64 66 +2
Methods 0 0
Messages 0 0
Branches 3 3
===================================
+ Hits 64 66 +2
Misses 0 0
Partials 0 0
Powered by Codecov. Last update ef8b88f...791afdf
I think you misread the JMH output:
21734.998 ±(99.9%) 802.984 ns/op
vs 19520.580 ±(99.9%) 381.775 ns/op
- the confidence interval is smaller/halved in that measurement, but the performance improvement is much smaller (21.7k to 19.5k). I'm in fact a little surprised that you get a performance improvement at all, given that the . size()
calls might be inlineable. But I suppose it's possible for the size of the list to change outside of this method, so it's probably a good change.
I would be interested in seeing the JMH test you were using, as well as if there are any benefits from the changes you made to the .thenApply
lambda (as in, comparing original/optimise array creation/optimise list creation/optimise both). That array size should be an inlineable constant, so it would be a bit surprising to me if that change has any impact.
We are running the benchmark with java.util.Collections$CopiesList
which has some quirks since it is a virtual list of the same element (final int n; final E element;
). Thus in the benchmark we are mostly comparing the differences due to the array allocations and it's hard to reason about the list being inlined.
I think the benchmark should be updated to use ArrayList
with distinct instances of CompletableFuture
s, and additionally those futures should be reset occasionally so that the benchmark covers not-yet-completed futures.
Of course this is a micro benchmark so the differences in performance are minuscule. The point of the benchmark was to prove that the old implementation (using streams) was extremely slow in comparison.
JMH for the old code => 802.984 ns/op
JMH for the new code => 381.775 ns/op