Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

System.IO.Compression: Make the ZLib BestCompression 6 #5458

Merged
merged 1 commit into from
Jan 15, 2016
Merged

System.IO.Compression: Make the ZLib BestCompression 6 #5458

merged 1 commit into from
Jan 15, 2016

Conversation

ianhays
Copy link
Contributor

@ianhays ianhays commented Jan 15, 2016

CompressionLevel 6 is what we used to use and we changed it in #4589 because we didn't see any perf regressions in doing so. With more testing, it has become clear that moving from 6 to 9 severely hurt perf in some scenarios so it's being reverted back to 6.

resolves #4475

@stephentoub @eerhardt @bjjones

Perf results coming in subsequent comments.

@@ -72,7 +72,7 @@ public enum CompressionLevel : int
{
NoCompression = 0,
BestSpeed = 1,
BestCompression = 9, // Refer to "How to choose a compression level" above.
BestCompression = 6, // Refer to "How to choose a compression level" above.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is the correct change. Zlib's "BestCompression" value is 9, so if we have an enum value here called "BestCompression", its value should match zlib's value.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of hard-coding our "Optimal" value to be "6" in zlib, I think our "Optimal" value should map to "-1"/"Z_DEFAULT_COMPRESSION" in zlib. See my comments on https://github.com/dotnet/corefx/issues/4475 for reasoning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of hard-coding our "Optimal" value to be "6" in zlib, I think our "Optimal" value should map to "-1"/"Z_DEFAULT_COMPRESSION" in zlib.

I agree with that.

The changes will result in a pattern like so:

•CompressionLevel.Optimal => ZlibNative.CompressionLevel.DefaultCompression => Z_DEFAULT_COMPRESSION (-1)
•CompressionLevel.Fastest => ZlibNative.CompressionLevel.BestSpeed=> Z_BEST_SPEED (1)
•CompressionLevel.NoCompression => ZlibNative.CompressionLevel.NoCompression=> Z_NO_COMPRESSION (0)

Does that look right to you? ZlibNative.CompressionLevel.BestCompression will be removed since we won't be using it anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Does that look right to you?

This mapping looks perfect to me.

ZlibNative.CompressionLevel.BestCompression will be removed since we won't be using it anywhere.

Yep - no reason to leave it in if it isn't used.

One additional thing to update is the native "PAL" layer that ensures our hard-coded values match the zlib we are compiling against:

https://github.com/dotnet/corefx/blob/master/src/Native/System.IO.Compression.Native/pal_zlib.cpp#L21-L23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I missed those. Updated.

@ianhays
Copy link
Contributor Author

ianhays commented Jan 15, 2016

Test File Level 6 Level 9 SIZE - 6 SIZE - 9 % Difference
Compress_Canterbury(fileName: ""alice29.txt"") " 8.917448 13.37116 54398 54164 0.004302
Compress_Canterbury(fileName: ""asyoulik.txt"")" 8.080385 9.819347 48891 48772 0.002434
Compress_Canterbury(fileName: ""cp.html"") " 0.537981 0.611655 7955 7934 0.00264
Compress_Canterbury(fileName: ""fields.c"") " 0.222086 0.273522 3116 3109 0.002246
Compress_Canterbury(fileName: ""grammar.lsp"") " 0.05302 0.052567 1216 1216 0
Compress_Canterbury(fileName: ""kennedy.xls"") " 45.70004 469.9029 203986 207023 -0.01489
Compress_Canterbury(fileName: ""lcet10.txt"") " 25.64531 31.46296 144898 144433 0.003209
Compress_Canterbury(fileName: ""plrabn12.txt"")" 37.71344 56.05795 195255 194326 0.004758
Compress_Canterbury(fileName: ""ptt5"") " 11.76278 79.78852 56459 52215 0.07517
Compress_Canterbury(fileName: ""sum"") " 1.809826 12.39126 12984 12832 0.011707
Compress_Canterbury(fileName: ""xargs.1"") " 0.064139 0.060835 1730 1730 0

EDIT: Updated with sizes as well

@stephentoub
Copy link
Member

@ianhays, what about size differences?

@ianhays
Copy link
Contributor Author

ianhays commented Jan 15, 2016

Updated my above comment with sizes.

CompressionLevel 6 is what we used to use and we changed it in #4589 because we didn't see any perf regressions in doing so. With more testing, it has become clear that moving from 6 to 9 severely hurt perf in some scenarios so it's being reverted to -1 which maps to 6.
@stephentoub
Copy link
Member

Updated my above comment with sizes.

Thanks.

/// ZLib definitions, which map to our public NoCompression, Fastest, and Optimal respectively.
/// <p><em>Optimal Compression:</em></p>
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.BestCompression;</code> <br />
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.DefaultCompression;</code> <br />
Copy link
Member

Choose a reason for hiding this comment

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

Are below comments around windowBits, etc., still correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@eerhardt
Copy link
Member

LGTM.

@stephentoub
Copy link
Member

LGTM

@ianhays
Copy link
Contributor Author

ianhays commented Jan 15, 2016

Thanks folks!

ianhays pushed a commit that referenced this pull request Jan 15, 2016
System.IO.Compression: Make the ZLib BestCompression 6
@ianhays ianhays merged commit 78ad63e into dotnet:master Jan 15, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
System.IO.Compression: Make the ZLib BestCompression 6

Commit migrated from dotnet/corefx@78ad63e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change ZLib Optimal CompressionLevel on Unix
4 participants