jetty / jetty/jetty.project

Perf: `DynamicCapacity.size()` calls megamorphic `RetainableByteBuffer.remaining()`

Open
#13,404 1 comment 0 reactions 1 assignee Claimed by @lorban View on GitHub
Bug Stale
Dominant language
Java
Stars
4.1k
Forks
2k
Avg merge
3d 56m
Merged PRs (30d)
48

Description

**Jetty version(s)**
12.1.x

**Description**
A H2 benchmark revealed that the H2 `Generator` often calls `DynamicCapacity.ensure()` (via the different `put*()` methods) which itself calls `size()` which eventually calls `RetainableByteBuffer.remaining()` method in a loop.

Async-profiler revealed that `RetainableByteBuffer.remaining()` is megamorphic, so calling it is very expensive and that is done very liberally as the assumption is that this call would be cheap.

This should be improved, maybe by tracking the `RetainableByteBuffer` remaining bytes in another variable instead of summing them up each time `size()` is called?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.