Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory copy in zstd compression #7681

Merged
merged 4 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Change http code on create index API with bad input raising NotXContentException from 500 to 400 ([#4773](https://github.com/opensearch-project/OpenSearch/pull/4773))
- Change http code for DecommissioningFailedException from 500 to 400 ([#5283](https://github.com/opensearch-project/OpenSearch/pull/5283))
- Improve summary error message for invalid setting updates ([#4792](https://github.com/opensearch-project/OpenSearch/pull/4792))
- Reduce memory copy in zstd compression ([#7681](https://github.com/opensearch-project/OpenSearch/pull/7681))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void doCompress(byte[] bytes, int offset, int length, ZstdCompressCtx cc
return;
}
final int maxCompressedLength = (int) Zstd.compressBound(length);
compressedBuffer = ArrayUtil.grow(compressedBuffer, maxCompressedLength);
compressedBuffer = ArrayUtil.growNoCopy(compressedBuffer, maxCompressedLength);
reta marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down Expand Up @@ -139,7 +139,7 @@ private void doDecompress(DataInput in, ZstdDecompressCtx dctx, BytesRef bytes,
return;
}

compressedBuffer = ArrayUtil.grow(compressedBuffer, compressedLength);
compressedBuffer = ArrayUtil.growNoCopy(compressedBuffer, compressedLength);
in.readBytes(compressedBuffer, 0, compressedLength);

bytes.bytes = ArrayUtil.grow(bytes.bytes, bytes.length + decompressedLen);
Expand All @@ -161,7 +161,7 @@ public void decompress(DataInput in, int originalLength, int offset, int length,
}
final int dictLength = in.readVInt();
final int blockLength = in.readVInt();
bytes.bytes = ArrayUtil.grow(bytes.bytes, dictLength);
bytes.bytes = ArrayUtil.growNoCopy(bytes.bytes, dictLength);
bytes.offset = bytes.length = 0;

try (ZstdDecompressCtx dctx = new ZstdDecompressCtx()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void compress(byte[] bytes, int offset, int length, DataOutput out) thro
}

final int maxCompressedLength = (int) Zstd.compressBound(l);
compressedBuffer = ArrayUtil.grow(compressedBuffer, maxCompressedLength);
compressedBuffer = ArrayUtil.growNoCopy(compressedBuffer, maxCompressedLength);

int compressedSize = (int) Zstd.compressByteArray(
compressedBuffer,
Expand Down Expand Up @@ -151,7 +151,7 @@ public void decompress(DataInput in, int originalLength, int offset, int length,
if (compressedLength == 0) {
return;
}
compressed = ArrayUtil.grow(compressed, compressedLength);
compressed = ArrayUtil.growNoCopy(compressed, compressedLength);
in.readBytes(compressed, 0, compressedLength);

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