Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4555

Getter of binary field in Java creates unnecessary copy

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.11.0
    • 0.12.0
    • Java - Compiler
    • None

    Description

      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:

      struct StructWithBinary {
             1: required binary field;
      }
      

      a portion of the generated code for this is:

        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;
        }
      

      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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              TV4Fun Joel Croteau
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: