Skip to content

Commit 1edf16f

Browse files
committed
1. reduce memory copy in zstd compression
Signed-off-by: luyuncheng <[email protected]>
1 parent 63834d9 commit 1edf16f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sandbox/plugins/custom-codecs/src/main/java/org/opensearch/index/codec/customcodecs/ZstdCompressionMode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void doCompress(byte[] bytes, int offset, int length, ZstdCompressCtx cc
7777
return;
7878
}
7979
final int maxCompressedLength = (int) Zstd.compressBound(length);
80-
compressedBuffer = ArrayUtil.grow(compressedBuffer, maxCompressedLength);
80+
compressedBuffer = ArrayUtil.growNoCopy(compressedBuffer, maxCompressedLength);
8181

8282
int compressedSize = cctx.compressByteArray(compressedBuffer, 0, compressedBuffer.length, bytes, offset, length);
8383

@@ -139,7 +139,7 @@ private void doDecompress(DataInput in, ZstdDecompressCtx dctx, BytesRef bytes,
139139
return;
140140
}
141141

142-
compressedBuffer = ArrayUtil.grow(compressedBuffer, compressedLength);
142+
compressedBuffer = ArrayUtil.growNoCopy(compressedBuffer, compressedLength);
143143
in.readBytes(compressedBuffer, 0, compressedLength);
144144

145145
bytes.bytes = ArrayUtil.grow(bytes.bytes, bytes.length + decompressedLen);
@@ -161,7 +161,7 @@ public void decompress(DataInput in, int originalLength, int offset, int length,
161161
}
162162
final int dictLength = in.readVInt();
163163
final int blockLength = in.readVInt();
164-
bytes.bytes = ArrayUtil.grow(bytes.bytes, dictLength);
164+
bytes.bytes = ArrayUtil.growNoCopy(bytes.bytes, dictLength);
165165
bytes.offset = bytes.length = 0;
166166

167167
try (ZstdDecompressCtx dctx = new ZstdDecompressCtx()) {

sandbox/plugins/custom-codecs/src/main/java/org/opensearch/index/codec/customcodecs/ZstdNoDictCompressionMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void compress(byte[] bytes, int offset, int length, DataOutput out) thro
8383
}
8484

8585
final int maxCompressedLength = (int) Zstd.compressBound(l);
86-
compressedBuffer = ArrayUtil.grow(compressedBuffer, maxCompressedLength);
86+
compressedBuffer = ArrayUtil.growNoCopy(compressedBuffer, maxCompressedLength);
8787

8888
int compressedSize = (int) Zstd.compressByteArray(
8989
compressedBuffer,
@@ -151,7 +151,7 @@ public void decompress(DataInput in, int originalLength, int offset, int length,
151151
if (compressedLength == 0) {
152152
return;
153153
}
154-
compressed = ArrayUtil.grow(compressed, compressedLength);
154+
compressed = ArrayUtil.growNoCopy(compressed, compressedLength);
155155
in.readBytes(compressed, 0, compressedLength);
156156

157157
int l = Math.min(blockLength, originalLength - offsetInBlock);

0 commit comments

Comments
 (0)