Skip to content

Commit

Permalink
More comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed Mar 26, 2024
1 parent 676e11e commit 145c567
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public String toString() {

private static final class ZstdDecompressor extends Decompressor {

// Buffer for copying between the DataInput and native memory
final byte[] copyBuffer = new byte[4096];

ZstdDecompressor() {}
Expand Down Expand Up @@ -153,6 +154,7 @@ public Decompressor clone() {
private static class ZstdCompressor extends Compressor {

final int level;
// Buffer for copying between the DataInput and native memory
final byte[] copyBuffer = new byte[4096];

ZstdCompressor(int level) {
Expand All @@ -171,6 +173,12 @@ public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws I

final int compressBound = zstd.compressBound(srcLen);

// NOTE: We are allocating/deallocating native buffers on each call. We could save allocations by reusing these buffers, though
// this would come at the expense of higher permanent memory usage. Benchmarks suggested that there is some performance to save
// there, but it wouldn't be a game changer either.
// Also note that calls to #compress implicitly allocate memory under the hood for e.g. hash tables and chain tables that help
// identify duplicate strings. So if we wanted to avoid allocating memory on every compress call, we should also look into
// reusing compression contexts, which are not small and would increase permanent memory usage as well.
try (
CloseableByteBuffer src = nativeAccess.newBuffer(srcLen);
CloseableByteBuffer dest = nativeAccess.newBuffer(compressBound)
Expand Down

0 comments on commit 145c567

Please sign in to comment.