lz4-java icon indicating copy to clipboard operation
lz4-java copied to clipboard

Double copying in LZ4UnsafeUtils.safeIncrementalCopy

Open mtopolnik opened this issue 10 years ago • 0 comments

Here the line which safely copies a byte is followed by a line which unsafely copies the byte:

  static void safeIncrementalCopy(byte[] dest, int matchOff, int dOff, int matchLen) {
    for (int i = 0; i < matchLen; ++i) {
      dest[dOff + i] = dest[matchOff + i];
      writeByte(dest, dOff + i, readByte(dest, matchOff + i));
    }
  }

I have measured the impact of deleting one line or the other; the clear winner is the simple Java idiom: dest[dOff + i] = dest[matchOff + i]; My measurement on data which is a simple repetition of byte values 0, 1, 2, ..., 255 shows very poor peformance with the 1.3 release version of LZ4 Unsafe decompressor; this one change (deleting writeBytes above) doubles the performance.

mtopolnik avatar Jun 21 '15 17:06 mtopolnik