replay: optimize decompressZST with pre-allocated buffer (#33562)

improve decompressZST
pull/33449/head
Dean Lee 8 months ago committed by GitHub
parent dcbeda1e85
commit fd893dfcb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      tools/replay/util.cc

@ -329,8 +329,17 @@ std::string decompressZST(const std::byte *in, size_t in_size, std::atomic<bool>
// Initialize input and output buffers
ZSTD_inBuffer input = {in, in_size, 0};
// Estimate and reserve memory for decompressed data
size_t estimatedDecompressedSize = ZSTD_getFrameContentSize(in, in_size);
if (estimatedDecompressedSize == ZSTD_CONTENTSIZE_ERROR || estimatedDecompressedSize == ZSTD_CONTENTSIZE_UNKNOWN) {
estimatedDecompressedSize = in_size * 2; // Use a fallback size
}
std::string decompressedData;
const size_t bufferSize = ZSTD_DStreamOutSize(); // recommended output buffer size
decompressedData.reserve(estimatedDecompressedSize);
const size_t bufferSize = ZSTD_DStreamOutSize(); // Recommended output buffer size
std::string outputBuffer(bufferSize, '\0');
while (input.pos < input.size && !(abort && *abort)) {

Loading…
Cancel
Save