vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

Reduce InboundBuffer pending queue's allocation pressure

Open franz1981 opened this issue 2 years ago • 3 comments

InboundBuffer's allocation create 16 pending entries by default while it could delay it when the initial size information is available. This change is going to lazy allocate it: it's less elegant due to the many null checks, but it's effective to reduce allocations in the hot paths. Subsequent allocations will make uses of the ArrayDeque enlarging strategy but starting with a much lower number (double capacity, but starting from 1 instead of 16)

franz1981 avatar May 26 '22 19:05 franz1981

image

This is screen from JFR allocation recording of Techempower's plaintext, showing this as one of the top allocators

franz1981 avatar May 26 '22 19:05 franz1981

in which case does it improve allocation ?

vietj avatar May 30 '22 06:05 vietj

In the cases of 0 -> 15 pending elements, but the most benefit come when there are none or very few . ArrayDeque is not like ArrayList that defer the real allocation: it allocates 16 elements by default, causing useless garbage to be created

franz1981 avatar May 30 '22 07:05 franz1981

@vietj ping on this bud

franz1981 avatar Feb 16 '23 13:02 franz1981

thanks for the contrib @franz1981

vietj avatar Feb 21 '23 16:02 vietj