Skip to content

ArrayRetainableByteBufferPool inefficiently calculates bucket indices #8810

Closed
@lorban

Description

@lorban
Contributor

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

changed the title [-]Performance: `ArrayRetainableByteBufferPool.bucketFor()` inefficiently calculates bucket indices[/-] [+]`ArrayRetainableByteBufferPool.bucketFor()` inefficiently calculates bucket indices[/+] on Nov 1, 2022
changed the title [-]`ArrayRetainableByteBufferPool.bucketFor()` inefficiently calculates bucket indices[/-] [+]`ArrayRetainableByteBufferPool` inefficiently calculates bucket indices[/+] on Nov 1, 2022
lorban

lorban commented on Nov 1, 2022

@lorban
ContributorAuthor

Here's an async profiler flame graph that shows ArrayRetainableByteBufferPool.bucketFor() is showing up almost 3% of the time: async-profiler-cpu.zip

joakime

joakime commented on Nov 10, 2022

@joakime
Contributor

@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

sbordet commented on Nov 10, 2022

@sbordet
Contributor

@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

lorban commented on Nov 10, 2022

@lorban
ContributorAuthor

@joakime It's not going to have much impact, no in terms of reliability (we're just replacing Integers with ints) nor in terms of performance (the AdaptiveExecutionStrategy 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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @joakime@sbordet@lorban

    Issue actions

      `ArrayRetainableByteBufferPool` inefficiently calculates bucket indices · Issue #8810 · jetty/jetty.project