Closed
Description
Jetty version(s)
10, 11, 12
Enhancement Description
The ArrayRetainableByteBufferPool.bucketFor()
method is on the fast path of every served request, and it delegates its index calculation to a Function<Integer, Integer>
lambda. This implies boxing and unboxing are happening each time a bucket must be chosen, and this inefficiency started appearing in profiling reports.
This code should be modified so that no boxing/unboxing is done anymore. A simple way would be to replace the Function<Integer, Integer>
lambda with a custom IntIntFunction
one for instance.
Activity
[-]Performance: `ArrayRetainableByteBufferPool.bucketFor()` inefficiently calculates bucket indices[/-][+]`ArrayRetainableByteBufferPool.bucketFor()` inefficiently calculates bucket indices[/+][-]`ArrayRetainableByteBufferPool.bucketFor()` inefficiently calculates bucket indices[/-][+]`ArrayRetainableByteBufferPool` inefficiently calculates bucket indices[/+]lorban commentedon Nov 1, 2022
Here's an async profiler flame graph that shows
ArrayRetainableByteBufferPool.bucketFor()
is showing up almost 3% of the time: async-profiler-cpu.zipjoakime commentedon Nov 10, 2022
@lorban do you want to do this for the upcoming Jetty 10 / Jetty 11 releases?
Or postpone this? (if so, move this to the next project)
sbordet commentedon Nov 10, 2022
@joakime @lorban I'll take this, there is
java.util.function.IntUnaryOperator
that has exactly the right signature and should have been used from the beginning.lorban commentedon Nov 10, 2022
@joakime It's not going to have much impact, no in terms of reliability (we're just replacing
Integer
s withint
s) nor in terms of performance (theAdaptiveExecutionStrategy
bottleneck is hiding this one) so it doesn't matter too much.But we did agree that it is too late for #8762 to be included in the upcoming release.
12 remaining items