Factor out less common code-path into own method to allow inlining. (#8590)
Motivation: During benchmarks two methods showed up as "hot method too big". We can easily make these smaller by factor out some less common code-path to an extra method and so allow inlining. Modifications: Factor out less common code path to an extra method. Result: Hot methods can be inlined.
This commit is contained in:
parent
af34287fd1
commit
af63626777
@ -434,21 +434,9 @@ public final class ChannelOutboundBuffer {
|
|||||||
}
|
}
|
||||||
nioBuffers[nioBufferCount++] = nioBuf;
|
nioBuffers[nioBufferCount++] = nioBuf;
|
||||||
} else {
|
} else {
|
||||||
ByteBuffer[] nioBufs = entry.bufs;
|
// The code exists in an extra method to ensure the method is not too big to inline as this
|
||||||
if (nioBufs == null) {
|
// branch is not very likely to get hit very frequently.
|
||||||
// cached ByteBuffers as they may be expensive to create in terms
|
nioBufferCount = nioBuffers(entry, buf, nioBuffers, nioBufferCount, maxCount);
|
||||||
// of Object allocation
|
|
||||||
entry.bufs = nioBufs = buf.nioBuffers();
|
|
||||||
}
|
|
||||||
for (int i = 0; i < nioBufs.length && nioBufferCount < maxCount; ++i) {
|
|
||||||
ByteBuffer nioBuf = nioBufs[i];
|
|
||||||
if (nioBuf == null) {
|
|
||||||
break;
|
|
||||||
} else if (!nioBuf.hasRemaining()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
nioBuffers[nioBufferCount++] = nioBuf;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (nioBufferCount == maxCount) {
|
if (nioBufferCount == maxCount) {
|
||||||
break;
|
break;
|
||||||
@ -463,6 +451,25 @@ public final class ChannelOutboundBuffer {
|
|||||||
return nioBuffers;
|
return nioBuffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int nioBuffers(Entry entry, ByteBuf buf, ByteBuffer[] nioBuffers, int nioBufferCount, int maxCount) {
|
||||||
|
ByteBuffer[] nioBufs = entry.bufs;
|
||||||
|
if (nioBufs == null) {
|
||||||
|
// cached ByteBuffers as they may be expensive to create in terms
|
||||||
|
// of Object allocation
|
||||||
|
entry.bufs = nioBufs = buf.nioBuffers();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < nioBufs.length && nioBufferCount < maxCount; ++i) {
|
||||||
|
ByteBuffer nioBuf = nioBufs[i];
|
||||||
|
if (nioBuf == null) {
|
||||||
|
break;
|
||||||
|
} else if (!nioBuf.hasRemaining()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
nioBuffers[nioBufferCount++] = nioBuf;
|
||||||
|
}
|
||||||
|
return nioBufferCount;
|
||||||
|
}
|
||||||
|
|
||||||
private static ByteBuffer[] expandNioBufferArray(ByteBuffer[] array, int neededSpace, int size) {
|
private static ByteBuffer[] expandNioBufferArray(ByteBuffer[] array, int neededSpace, int size) {
|
||||||
int newCapacity = array.length;
|
int newCapacity = array.length;
|
||||||
do {
|
do {
|
||||||
|
@ -793,17 +793,9 @@ public final class NioEventLoop extends SingleThreadEventLoop {
|
|||||||
selectCnt = 1;
|
selectCnt = 1;
|
||||||
} else if (SELECTOR_AUTO_REBUILD_THRESHOLD > 0 &&
|
} else if (SELECTOR_AUTO_REBUILD_THRESHOLD > 0 &&
|
||||||
selectCnt >= SELECTOR_AUTO_REBUILD_THRESHOLD) {
|
selectCnt >= SELECTOR_AUTO_REBUILD_THRESHOLD) {
|
||||||
// The selector returned prematurely many times in a row.
|
// The code exists in an extra method to ensure the method is not too big to inline as this
|
||||||
// Rebuild the selector to work around the problem.
|
// branch is not very likely to get hit very frequently.
|
||||||
logger.warn(
|
selector = selectRebuildSelector(selectCnt);
|
||||||
"Selector.select() returned prematurely {} times in a row; rebuilding Selector {}.",
|
|
||||||
selectCnt, selector);
|
|
||||||
|
|
||||||
rebuildSelector();
|
|
||||||
selector = this.selector;
|
|
||||||
|
|
||||||
// Select again to populate selectedKeys.
|
|
||||||
selector.selectNow();
|
|
||||||
selectCnt = 1;
|
selectCnt = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -826,6 +818,21 @@ public final class NioEventLoop extends SingleThreadEventLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Selector selectRebuildSelector(int selectCnt) throws IOException {
|
||||||
|
// The selector returned prematurely many times in a row.
|
||||||
|
// Rebuild the selector to work around the problem.
|
||||||
|
logger.warn(
|
||||||
|
"Selector.select() returned prematurely {} times in a row; rebuilding Selector {}.",
|
||||||
|
selectCnt, selector);
|
||||||
|
|
||||||
|
rebuildSelector();
|
||||||
|
Selector selector = this.selector;
|
||||||
|
|
||||||
|
// Select again to populate selectedKeys.
|
||||||
|
selector.selectNow();
|
||||||
|
return selector;
|
||||||
|
}
|
||||||
|
|
||||||
private void selectAgain() {
|
private void selectAgain() {
|
||||||
needsToSelectAgain = false;
|
needsToSelectAgain = false;
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user