From 3feea108db690f880f6e30e6e8f974cfbb78eee3 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 4 Oct 2020 00:09:55 +0200 Subject: DiscIO: Decrease RAM usage during zstd compression By calling ZSTD_CCtx_setPledgedSrcSize, we can let zstd know how large a chunk is going to be before which start compressing it, which lets zstd avoid allocating more memory than needed for various internal buffers. This greatly reduces the RAM usage when using a high compression level with a small chunk size, and doesn't have much of an effect in other circumstances. A side effect of calling ZSTD_CCtx_setPledgedSrcSize is that zstd by default will write the uncompressed size into the compressed data stream as metadata. In order to save space, and since the decompressed size can be figured out through the structure of the RVZ format anyway, we disable writing the uncompressed size by setting ZSTD_c_contentSizeFlag to 0. --- Source/Core/DiscIO/WIABlob.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/DiscIO/WIABlob.cpp') diff --git a/Source/Core/DiscIO/WIABlob.cpp b/Source/Core/DiscIO/WIABlob.cpp index 4d4b104242..999d3136ac 100644 --- a/Source/Core/DiscIO/WIABlob.cpp +++ b/Source/Core/DiscIO/WIABlob.cpp @@ -1040,7 +1040,7 @@ std::optional> WIARVZFileReader::Compress(Compressor* compr { if (compressor) { - if (!compressor->Start() || !compressor->Compress(data, size) || !compressor->End()) + if (!compressor->Start(size) || !compressor->Compress(data, size) || !compressor->End()) return std::nullopt; data = compressor->GetData(); @@ -1564,7 +1564,7 @@ WIARVZFileReader::ProcessAndCompress(CompressThreadState* state, CompressPa if (state->compressor) { - if (!state->compressor->Start()) + if (!state->compressor->Start(entry.exception_lists.size() + entry.main_data.size())) return ConversionResultCode::InternalError; } -- cgit v1.2.3