[ 
https://issues.apache.org/jira/browse/AVRO-1282?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13612586#comment-13612586
 ] 

Leo Romanoff commented on AVRO-1282:
------------------------------------

I have implemented an initial version of the Unsafe-based 
serialization/deserialization. It uses Unsafe (when it is available) to 
read/write fields of an object. I can see that it improves performance of 
reflection-based (de)serialization by a factor of two. This is actually less 
than I expected. 

One of the problems that I see is that read/write methods work with Objects. It 
means that when reading/writing primitive types they are being boxed and 
unboxed all the time. It would be cool to improve it.
How about introducing setIntField, setFloatField, setDoubleField, 
setShortField, setXXXField in GenericData? By default it would invoke setField 
for all of them. But it can be redefined by derived classes, i.e. ReflectData. 
Then the GenericDataReader#read() method could read a primitive type and write 
a primitive type without all those boxing/unboxing.
What do you think?
                
> Make use of the sun.misc.Unsafe class during serialization if a JDK supports 
> it
> -------------------------------------------------------------------------------
>
>                 Key: AVRO-1282
>                 URL: https://issues.apache.org/jira/browse/AVRO-1282
>             Project: Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.7.4
>            Reporter: Leo Romanoff
>            Priority: Minor
>
> Unsafe can be used to significantly speed up serialization process, if a JDK 
> implementation supports java.misc.Unsafe properly. Most JDKs running on PCs 
> support it. Some platforms like Android lack a proper support for Unsafe yet.
> There are two possibilities to use Unsafe for serialization:
> 1) Very quick access to the fields of objects. It is way faster than with the 
> reflection-based approach using Field.get/set
> 2) Input and Output streams can be using Unsafe to perform very quick 
> input/output.
>  
> 3) More over, Unsafe makes it possible to serialize to/deserialize from 
> off-heap memory directly and very quickly, without any intermediate buffers 
> allocated on heap. There is virtually no overhead compared to the usual byte 
> arrays.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to