From 32627d712a1f9dfabbb0d037c7bc06f19586edec Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Tue, 3 Nov 2020 12:08:43 -0800 Subject: [PATCH] Avoid auto boxing in PoolChunk#removeAvailRun (#10769) Motivation: PoolChunk maintains multiple PriorityQueue collections. The usage of PoolChunk#removeAvailRun unboxes the Long values to long, and then this method uses queue.remove(..) which will auto box the value back to Long. This creates unnecessary allocations via Long.valueOf(long). Modifications: - Adjust method signature and usage of PoolChunk#removeAvailRun to avoid boxing Result: Less allocations as a result of PoolChunk#removeAvailRun. --- buffer/src/main/java/io/netty/buffer/PoolChunk.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/PoolChunk.java b/buffer/src/main/java/io/netty/buffer/PoolChunk.java index a1386ccd91..3723731a88 100644 --- a/buffer/src/main/java/io/netty/buffer/PoolChunk.java +++ b/buffer/src/main/java/io/netty/buffer/PoolChunk.java @@ -250,13 +250,13 @@ final class PoolChunk implements PoolChunkMetric { assert pre == null; } - private void removeAvailRun(long handle) { + private void removeAvailRun(Long handle) { int pageIdxFloor = arena.pages2pageIdxFloor(runPages(handle)); PriorityQueue queue = runsAvail[pageIdxFloor]; removeAvailRun(queue, handle); } - private void removeAvailRun(PriorityQueue queue, long handle) { + private void removeAvailRun(PriorityQueue queue, Long handle) { queue.remove(handle); int runOffset = runOffset(handle); @@ -335,9 +335,9 @@ final class PoolChunk implements PoolChunkMetric { //get run with min offset in this queue PriorityQueue queue = runsAvail[queueIdx]; - long handle = queue.poll(); + Long handle = queue.poll(); - assert !isUsed(handle); + assert handle != null && !isUsed(handle); removeAvailRun(queue, handle);