Avro
  1. Avro
  2. AVRO-985

Remove byte-by-byte copying in RecordBuilderBase.defaultValue for non-complex types

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6.1
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      In one section of RecordBuilderBase.defaultValue(Field) (quoted below) a bytewise copy of the default object is created based on the JSON value provided. However, this is an extremely inefficient operation and causes large slowdowns when building large object sets, including latency spikes when the binary encoder flushes.

      A simple workaround for a majority of cases would be to have a separate code path for "primitives" (fixed, string, boolean, int, double, enum, float, bytes) that allows direct creation rather than a full bytewise copy (and subsequent deep copy).

      RecordBuilderBase.java:

          // If not cached, get the default Java value by encoding the default JSON
          // value and then decoding it:
          if (defaultValue == null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            encoder = EncoderFactory.get().binaryEncoder(baos, encoder);
            ResolvingGrammarGenerator.encode(
                encoder, field.schema(), defaultJsonValue);
            encoder.flush();
            decoder = DecoderFactory.get().binaryDecoder(
                baos.toByteArray(), decoder);
            defaultValue = new GenericDatumReader(
                field.schema()).read(null, decoder);
            defaultSchemaValues.putIfAbsent(field.pos(), defaultValue);
          }
      

        Issue Links

          Activity

          Hide
          Scott Carey added a comment -

          This is a big performance problem, We could use some sort of Avro Value API (perhaps simply GenericData and friends, in immutable form) instead of the JSON objecs to represent default values. Then, when serializing the serialized bytes can be cached instead and output, and when deserializing the immutable Generic object can be substituted.

          Show
          Scott Carey added a comment - This is a big performance problem, We could use some sort of Avro Value API (perhaps simply GenericData and friends, in immutable form) instead of the JSON objecs to represent default values. Then, when serializing the serialized bytes can be cached instead and output, and when deserializing the immutable Generic object can be substituted.

            People

            • Assignee:
              Unassigned
              Reporter:
              Douglas Kaminsky
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Development