Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3657

Computation of initial buffer size in OutputBuffer makes no sense

    XMLWordPrintableJSON

Details

    Description

      As you can see, OutputBuffer calls the superclass constructor in the following way:

      https://github.com/apache/avro/blame/1119b6eb5b92730b27e9798793bc67f192591c15/lang/java/trevni/core/src/main/java/org/apache/trevni/OutputBuffer.java#L32

       

      public OutputBuffer()

      { super((BLOCK_SIZE + BLOCK_SIZE) >> 2); }

       

      Before 3d51ba5e965561 change it was 

       

      public OutputBuffer()

      { super(BLOCK_SIZE + BLOCK_SIZE >> 2); }

       

      Which looked like the author did not know that >> has lower precedence than + and forgot to put parentheses. It looks like, the 3d51ba5e965561 change blindly applied static analyzer suggestions and added parentheses to preserve the current semantics. However, `(BLOCK_SIZE + BLOCK_SIZE) >> 2` is simply `BLOCK_SIZE / 2`.

       

      My suggestion is the following:

      • If everybody is fine with current behavior, let's update this to `super(BLOCK_SIZE / 2);` to avoid confusion.
      • If we would like to preserve the original author's intention to allocate 1.25x more, let's place the parentheses in another way: `super(BLOCK_SIZE + (BLOCK_SIZE >> 2));`

      Attachments

        Issue Links

          Activity

            People

              mgrigorov Martin Tzvetanov Grigorov
              lany Tagir Valeev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m