jawn icon indicating copy to clipboard operation
jawn copied to clipboard

Speed up ByteBuffer parsing

Open non opened this issue 10 years ago • 1 comments

This is relatively slow for some reason. Figure out why!

non avatar Jul 28 '15 16:07 non

@non A reason why ByteBuffer in JVM is slow is it generates TypeProfile https://wiki.openjdk.java.net/display/HotSpot/TypeProfile to resolve a single method from many ByteBuffer sub classes in Java standard libraries. So each ByteBuffer.get(i) call will look up the TypeProfile table and become slower than Array[Byte] lookup.

A workaround is extracting the internal buffer (array or off-heap) of ByteBuffer like this implementation: https://github.com/msgpack/msgpack-java/blob/develop/msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java

However this kind of implementation needs sun.misc.Unsafe and introduce some complexities to your code.

xerial avatar Aug 20 '18 19:08 xerial