Skip to content

Commit 5078967

Browse files
committed
benchmarks: Simplify reading Zlib input streams
1 parent 34aa201 commit 5078967

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

benchmarks/src/jmh/java/dev/freya02/discord/zstd/ZstdStreamingBenchmark.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,17 @@ public void zlib(ZlibDecompressorState decompressorState, ShardsState shardsStat
121121
@Benchmark
122122
public void zlibNoDeser(ZlibDecompressorState decompressorState, ShardsState shardsState, Blackhole blackhole) throws IOException {
123123
var decompressor = decompressorState.decompressor;
124-
var bytes = decompressorState.buf;
125124
for (List<TestChunks.Chunk> shard : shardsState.shards) {
126125
decompressor.reset();
127126
for (TestChunks.Chunk chunk : shard) {
128-
int currentlyDecompressedSize = 0;
129-
int expectedDecompressedSize = chunk.decompressed().length;
130127
try (InputStream inputStream = decompressor.createInputStream(chunk.zlibCompressed())) {
131-
// This is pretty stupid, #available() returns 1 even when there is no output to be read,
132-
// we want to avoid handling EOFException as it may be slow and does not represent real world usage,
133-
// checking `read < buf.length` is not viable since it can store data internally and returned in the next call.
134-
// So, we instead decompress until we have the known decompressed data length.
135-
do {
136-
var read = inputStream.read(bytes);
137-
currentlyDecompressedSize += read;
138-
blackhole.consume(bytes);
139-
} while (currentlyDecompressedSize < expectedDecompressedSize);
128+
while (true) {
129+
var read = inputStream.read(decompressorState.buf);
130+
blackhole.consume(decompressorState.buf);
131+
if (read <= 0) {
132+
break;
133+
}
134+
}
140135
}
141136
}
142137
}

0 commit comments

Comments
 (0)