Make sure we only create an Iterator during processSelectedKeys(..) if there is really something key to process. This cut down unneeded garbage that needs to get handled by the GC later. See #597

This commit is contained in:
norman 2012-09-13 09:45:55 +02:00
parent 79c33bdfc4
commit f1e00947a6
2 changed files with 12 additions and 0 deletions

View File

@ -456,6 +456,12 @@ abstract class AbstractNioWorker implements Worker {
}
private void processSelectedKeys(Set<SelectionKey> selectedKeys) throws IOException {
// check if the set is empty and if so just return to not create garbage by
// creating a new Iterator every time even if there is nothing to process.
// See https://github.com/netty/netty/issues/597
if (selectedKeys.isEmpty()) {
return;
}
for (Iterator<SelectionKey> i = selectedKeys.iterator(); i.hasNext();) {
SelectionKey k = i.next();
i.remove();

View File

@ -408,6 +408,12 @@ class NioClientSocketPipelineSink extends AbstractNioChannelSink {
}
private void processSelectedKeys(Set<SelectionKey> selectedKeys) {
// check if the set is empty and if so just return to not create garbage by
// creating a new Iterator every time even if there is nothing to process.
// See https://github.com/netty/netty/issues/597
if (selectedKeys.isEmpty()) {
return;
}
for (Iterator<SelectionKey> i = selectedKeys.iterator(); i.hasNext();) {
SelectionKey k = i.next();
i.remove();