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

DiscIO: Decrease RAM usage during zstd compression #9137

Merged
merged 1 commit into from Oct 14, 2020

Conversation

JosJuice
Copy link
Member

@JosJuice JosJuice commented Oct 7, 2020

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.

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.
@@ -1564,7 +1564,7 @@ WIARVZFileReader<RVZ>::ProcessAndCompress(CompressThreadState* state, CompressPa

if (state->compressor)
{
if (!state->compressor->Start())
if (!state->compressor->Start(entry.exception_lists.size() + entry.main_data.size()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to check that exceptions_list indeed stored bytes rather than exception structs (as the name would imply IMO). That's probably just because I'm unfamiliar with this code, though :)

Still, it might be worth renaming this member to exception_list_data for more clarity and for consistency with main_data in a followup PR?

@leoetlino leoetlino merged commit c3cdac4 into dolphin-emu:master Oct 14, 2020
10 checks passed
@JosJuice JosJuice deleted the zstd-ram-usage branch October 14, 2020 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants