Remove not needed intermediate collection while reading DatagramPackets in native transports

Motivation:

We used an intermediate collection to store the read DatagramPackets and only fired these through the pipeline once wewere done with the reading loop. This is not needed and can also increase memory usage.

Modifications:

Remove intermediate collection

Result:

Less overhead and possible less memory usage during read loop.
This commit is contained in:
Norman Maurer 2017-07-05 10:06:05 +02:00
parent 6d80c641e9
commit c318fc7cea
2 changed files with 8 additions and 16 deletions

View File

@ -431,7 +431,6 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
}
final class EpollDatagramChannelUnsafe extends AbstractEpollUnsafe {
private final List<Object> readBuf = new ArrayList<Object>();
@Override
public void connect(SocketAddress remote, SocketAddress local, ChannelPromise channelPromise) {
@ -514,7 +513,10 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
allocHandle.lastBytesRead(remoteAddress.receivedAmount());
data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead());
readBuf.add(new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));
readPending = false;
pipeline.fireChannelRead(
new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));
data = null;
} while (allocHandle.continueReading());
} catch (Throwable t) {
@ -524,12 +526,6 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
exception = t;
}
int size = readBuf.size();
for (int i = 0; i < size; i ++) {
readPending = false;
pipeline.fireChannelRead(readBuf.get(i));
}
readBuf.clear();
allocHandle.readComplete();
pipeline.fireChannelReadComplete();

View File

@ -403,7 +403,6 @@ public final class KQueueDatagramChannel extends AbstractKQueueChannel implement
}
final class KQueueDatagramChannelUnsafe extends AbstractKQueueUnsafe {
private final List<Object> readBuf = new ArrayList<Object>();
@Override
public void connect(SocketAddress remote, SocketAddress local, ChannelPromise channelPromise) {
@ -483,7 +482,10 @@ public final class KQueueDatagramChannel extends AbstractKQueueChannel implement
allocHandle.lastBytesRead(remoteAddress.receivedAmount());
data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead());
readBuf.add(new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));
readPending = false;
pipeline.fireChannelRead(
new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));
data = null;
} while (allocHandle.continueReading());
} catch (Throwable t) {
@ -493,12 +495,6 @@ public final class KQueueDatagramChannel extends AbstractKQueueChannel implement
exception = t;
}
int size = readBuf.size();
for (int i = 0; i < size; i ++) {
readPending = false;
pipeline.fireChannelRead(readBuf.get(i));
}
readBuf.clear();
allocHandle.readComplete();
pipeline.fireChannelReadComplete();