Use Netty ByteBuf Bulk Operations for Faster Deserialization (#40158) (#40339)

* Use bulk methods to read numbers faster from byte buffers
This commit is contained in:
Armin Braun 2019-03-24 19:08:51 +01:00 committed by GitHub
parent a30bf27b2f
commit 13d76239a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 2 deletions

View File

@ -28,7 +28,7 @@ import java.io.EOFException;
import java.io.IOException;
/**
* A Netty {@link io.netty.buffer.ByteBuf} based {@link org.elasticsearch.common.io.stream.StreamInput}.
* A Netty {@link ByteBuf} based {@link StreamInput}.
*/
class ByteBufStreamInput extends StreamInput {
@ -109,6 +109,39 @@ class ByteBufStreamInput extends StreamInput {
return len;
}
@Override
public short readShort() throws IOException {
try {
return buffer.readShort();
} catch (IndexOutOfBoundsException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public int readInt() throws IOException {
try {
return buffer.readInt();
} catch (IndexOutOfBoundsException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public long readLong() throws IOException {
try {
return buffer.readLong();
} catch (IndexOutOfBoundsException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public void reset() throws IOException {
buffer.resetReaderIndex();

View File

@ -226,6 +226,39 @@ class ByteBufUtils {
return len;
}
@Override
public short readShort() throws IOException {
try {
return buffer.readShort();
} catch (IndexOutOfBoundsException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public int readInt() throws IOException {
try {
return buffer.readInt();
} catch (IndexOutOfBoundsException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public long readLong() throws IOException {
try {
return buffer.readLong();
} catch (IndexOutOfBoundsException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public void reset() throws IOException {
buffer.resetReaderIndex();

View File

@ -20,6 +20,7 @@ package org.elasticsearch.common.io.stream;
import java.io.EOFException;
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
public class ByteBufferStreamInput extends StreamInput {
@ -76,6 +77,39 @@ public class ByteBufferStreamInput extends StreamInput {
buffer.get(b, offset, len);
}
@Override
public short readShort() throws IOException {
try {
return buffer.getShort();
} catch (BufferUnderflowException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public int readInt() throws IOException {
try {
return buffer.getInt();
} catch (BufferUnderflowException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public long readLong() throws IOException {
try {
return buffer.getLong();
} catch (BufferUnderflowException ex) {
EOFException eofException = new EOFException();
eofException.initCause(ex);
throw eofException;
}
}
@Override
public void reset() throws IOException {
buffer.reset();

View File

@ -415,7 +415,6 @@ public abstract class StreamInput extends InputStream {
return spare.toString();
}
public final float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}