Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-10619

Optimize the writeBytes in TermsHashPerField

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 9.2
    • 9.3
    • core/index
    • None
    • New

    Description

      Because we don't know the length of slice, writeBytes will always write byte one after another instead of writing a block of bytes.

      May be we could return both offset and length in ByteBlockPool#allocSlice?
      1. BYTE_BLOCK_SIZE is 32768, offset is at most 15 bits.
      2. slice size is at most 200, so it could fit in 8 bits.
      So we could put them together into an int -------- offset | length
      There are only two places where this function is used,the cost of change it is relatively small.

      When allocSlice could return the offset and length of new Slice, we could change writeBytes like below

      // write block of bytes each time
      while(remaining > 0 ) {
         int offsetAndLength = allocSlice(bytes, offset);
         length = min(remaining, (offsetAndLength & 0xff) - 1);
         offset = offsetAndLength >> 8;
         System.arraycopy(src, srcPos, bytePool.buffer, offset, length);
         remaining -= length;
         offset    += (length + 1);
      }
      

      If it could work, I'd like to raise a pr.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              tangdh tang donghai
              Votes:
              0 Vote for this issue
              Watchers:
              4 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 - 1.5h
                  1.5h