You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JDK 9 introduced a way to access a byte[] as other primitive types[1].
I threw together a quick jmh and (windows 64bit open JDK 11.0.6) found significant improvements for parsing longs and doubles and writing ints, longs and doubles. The other data types were essentially a wash.
Test
normal (ns/ops)
var handle (ns/ops)
ParseInt 1234567890abcdef
2.805
2.828
ParseInt fedcba0987654321
2.75
2.815
ParseLong 1234567890abcdef
3.863
2.776
ParseLong fedcba0987654321
3.882
3.045
ParseShort 1234567890abcdef
2.316
2.668
ParseShort fedcba0987654321
2.34
2.686
ParseDouble 1234567890abcdef
4.025
3.033
ParseDouble fedcba0987654321
4.009
3.044
ParseFloat 1234567890abcdef
3.258
3.01
ParseFloat fedcba0987654321
3.3
3.015
WriteInt 1234567890abcdef
1.189
0.821
WriteInt fedcba0987654321
1.195
0.816
WriteLong 1234567890abcdef
2.496
0.94
WriteLong fedcba0987654321
2.506
0.944
WriteShort 1234567890abcdef
0.876
0.894
WriteShort fedcba0987654321
0.878
0.894
WriteDouble 1234567890abcdef
2.596
1.271
WriteDouble fedcba0987654321
2.597
1.279
WriteFloat 1234567890abcdef
1.254
1.256
WriteFloat fedcba0987654321
1.262
1.323
These operations are all pretty fast already, but given how often they are done when we start doing a multi-release jar (or some other means of taking advantage of jdk9+ features) this is a pretty simple change to pick up a bit of performance.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
JDK 9 introduced a way to access a
byte[]
as other primitive types[1].I threw together a quick jmh and (windows 64bit open JDK 11.0.6) found significant improvements for parsing longs and doubles and writing ints, longs and doubles. The other data types were essentially a wash.
These operations are all pretty fast already, but given how often they are done when we start doing a multi-release jar (or some other means of taking advantage of jdk9+ features) this is a pretty simple change to pick up a bit of performance.
[1] - https://docs.oracle.com/javase/9/docs/api/java/lang/invoke/MethodHandles.html#byteArrayViewVarHandle-java.lang.Class-java.nio.ByteOrder-
[2] - https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java
Beta Was this translation helpful? Give feedback.
All reactions