[
https://issues.apache.org/jira/browse/AVRO-2696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17019052#comment-17019052
]
David Mollitor edited comment on AVRO-2696 at 1/19/20 10:35 PM:
----------------------------------------------------------------
{code:java}
int len = 1;
int bits = Float.floatToRawIntBits(f);
buf[pos] = (byte) ((bits) & 0xFF);
buf[pos + len++] = (byte) ((bits >>> 8) & 0xFF);
buf[pos + len++] = (byte) ((bits >>> 16) & 0xFF);
buf[pos + len++] = (byte) ((bits >>> 24) & 0xFF);
{code}
It's the only encoder / decoder in Avro that uses the 'len' counter, everything
else just hard-codes the offsets. Might explain the performance improvement.
was (Author: belugabehr):
{code:java}
int len = 1;
int bits = Float.floatToRawIntBits(f);
// hotspot compiler works well with this variant
buf[pos] = (byte) ((bits) & 0xFF);
buf[pos + len++] = (byte) ((bits >>> 8) & 0xFF);
buf[pos + len++] = (byte) ((bits >>> 16) & 0xFF);
buf[pos + len++] = (byte) ((bits >>> 24) & 0xFF);
{code}
It's the only encoder / decoder in Avro that uses the 'len' counter, everything
else just hard-codes the offsets. Might explain the performance improvement.
> Improve Avro Double and Float Encode Performance
> ------------------------------------------------
>
> Key: AVRO-2696
> URL: https://issues.apache.org/jira/browse/AVRO-2696
> Project: Apache Avro
> Issue Type: Improvement
> Reporter: David Mollitor
> Assignee: David Mollitor
> Priority: Minor
>
> I was looking at how Avro encodes Doubles and Floats and comparing it to
> Java's.
> So, I checked it out and found that the Java version for Floats is faster
> than Avro using the Avro perf tests:
> {code}
> # Avro Impl
> FloatTest.encode thrpt 3 273709210.133 ± 49629107.871 ops/s
> FloatTest.encode thrpt 3 271515727.631 ± 57405372.266 ops/s
> # Java Impl
> FloatTest.encode thrpt 3 278234438.923 ± 34633982.243 ops/s
> FloatTest.encode thrpt 3 284801936.136 ± 52273884.157 ops/s
> {code}
> Interestingly, I wasn't able to reproduce this gain with Doubles. Avro's
> version was faster. However, we can remove the bitwise mask (Java doesn't
> bother to do it).
> https://github.com/openjdk/jdk/blob/6bab0f539fba8fb441697846347597b4a0ade428/src/java.base/share/classes/java/io/Bits.java#L105
--
This message was sent by Atlassian Jira
(v8.3.4#803005)