You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Ben Podgursky (JIRA)" <ji...@apache.org> on 2018/04/13 00:33:00 UTC

[jira] [Commented] (THRIFT-4555) Getter of binary field in Java creates unnecessary copy

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

Ben Podgursky commented on THRIFT-4555:
---------------------------------------

It looks like this was introduced in THRIFT-2233.  We are looking at upgrading from 0.9.0 to 0.11 and this seems like it will introduce a huge amount of additional object creation – I haven't done aggressive performance testing yet, but we rely pretty heavily on binary fields.

I think ideally all the changes from THRIFT-2233 would be optional.  At the very least, setField/rightSize should only be called once. 

> Getter of binary field in Java creates unnecessary copy
> -------------------------------------------------------
>
>                 Key: THRIFT-4555
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4555
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler
>    Affects Versions: 0.11.0
>            Reporter: Joel Croteau
>            Priority: Major
>
> The get[field] method in generated Java code generates a new copy of a binary field every time it is called. This seems incredibly inefficient. Take a simple example struct:
> {code:java}
> struct StructWithBinary {
>        1: required binary field;
> }
> {code}
> a portion of the generated code for this is:
> {code:java}
>   public byte[] getField() {
>     setField(org.apache.thrift.TBaseHelper.rightSize(field));
>     return field == null ? null : field.array();
>   }
> ...
>   public StructWithBinary setField(java.nio.ByteBuffer field) {
>     this.field = org.apache.thrift.TBaseHelper.copyBinary(field);
>     return this;
>   }
> {code}
> So whenever getField is called, setField calls copyBinary and generates another copy. This adds quite a lot of overhead to the getter here and should be fixed.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)