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,6 +434,24 @@ public final class ChannelOutboundBuffer {
|
||||
}
|
||||
nioBuffers[nioBufferCount++] = nioBuf;
|
||||
} else {
|
||||
// The code exists in an extra method to ensure the method is not too big to inline as this
|
||||
// branch is not very likely to get hit very frequently.
|
||||
nioBufferCount = nioBuffers(entry, buf, nioBuffers, nioBufferCount, maxCount);
|
||||
}
|
||||
if (nioBufferCount == maxCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
entry = entry.next;
|
||||
}
|
||||
this.nioBufferCount = nioBufferCount;
|
||||
this.nioBufferSize = nioBufferSize;
|
||||
|
||||
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
|
||||
@ -449,18 +467,7 @@ public final class ChannelOutboundBuffer {
|
||||
}
|
||||
nioBuffers[nioBufferCount++] = nioBuf;
|
||||
}
|
||||
}
|
||||
if (nioBufferCount == maxCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
entry = entry.next;
|
||||
}
|
||||
this.nioBufferCount = nioBufferCount;
|
||||
this.nioBufferSize = nioBufferSize;
|
||||
|
||||
return nioBuffers;
|
||||
return nioBufferCount;
|
||||
}
|
||||
|
||||
private static ByteBuffer[] expandNioBufferArray(ByteBuffer[] array, int neededSpace, int size) {
|
||||
|
@ -793,17 +793,9 @@ public final class NioEventLoop extends SingleThreadEventLoop {
|
||||
selectCnt = 1;
|
||||
} else if (SELECTOR_AUTO_REBUILD_THRESHOLD > 0 &&
|
||||
selectCnt >= SELECTOR_AUTO_REBUILD_THRESHOLD) {
|
||||
// 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 = this.selector;
|
||||
|
||||
// Select again to populate selectedKeys.
|
||||
selector.selectNow();
|
||||
// The code exists in an extra method to ensure the method is not too big to inline as this
|
||||
// branch is not very likely to get hit very frequently.
|
||||
selector = selectRebuildSelector(selectCnt);
|
||||
selectCnt = 1;
|
||||
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() {
|
||||
needsToSelectAgain = false;
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user