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

Doug Cutting commented on AVRO-143:
-----------------------------------

> I wouldn't expect porting it to work with Avro to be too complicated, and 
> I've been thinking about doing it at some point.

That'd be great if you want to give this a stab!

The good news is that the Avro version only needs to generate two methods:
 - Object get(int field);
 - void set(int field, Object value);

The bad news is that these each need to contain a switch statement.  And, for 
primitive values, the getters need to, e.g., call something like Long#valueOf 
while the setters need to call something like Long#longValue to box and unbox 
things.

(Yes, perhaps it would be faster not to box.  But that would complicate things 
substantially.  We'd instead need to generate methods like 'Object 
readField(Object rec, int field, Decoder d, DatumReader in, Schema actual, 
Schema expected)' and 'void write(Object rec, int field, Encoder e, DatumWriter 
out)' methods.  For primitive types it could directly invoke the 
encoder/decoder methods, without boxing.  For non-primitives it would call back 
to a protected DatumReader/Writer method.  And we'd still need a setter method, 
so that we can set default values.  Etc.  Or we could totally abandon 
code-sharing with GenericData and directly call generated readers for each 
field's type.  But that would involve generating a lot more code, duplicating 
lots of delicate logic.  But, for now, the boxing doesn't seem to be a problem 
in benchmarks.)

> use ASM to accellerate reflection
> ---------------------------------
>
>                 Key: AVRO-143
>                 URL: https://issues.apache.org/jira/browse/AVRO-143
>             Project: Avro
>          Issue Type: Improvement
>          Components: java
>            Reporter: Doug Cutting
>
> Java reflection is very slow, about 100 times slower for field access than 
> normal Java code.  However reflection might be a useful tool for converting 
> existing codebases to use Avro.
> One could, using ASM (http://asm.ow2.org/) make existing compiled classes to 
> implement the SpecificRecord interface or something similar:
> http://hadoop.apache.org/avro/docs/current/api/java/org/apache/avro/specific/SpecificRecord.html
> This would make existing classes as fast to serialize as generated classes.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to