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

Allows changing lz4hc compression level #43

Merged
merged 9 commits into from
Oct 12, 2014
Merged

Allows changing lz4hc compression level #43

merged 9 commits into from
Oct 12, 2014

Conversation

linnaea
Copy link
Contributor

@linnaea linnaea commented Jul 27, 2014

This pull request fixes issue #37.

The modified test case only checks for compression level 1, 5, 9 and 13, which I believe should be sufficient. Testing all levels up to 17 may take a long time. (Adding level 17 alone adds 1 minute to the overall test time on my machine, which has a Core i5-4200U CPU.)

To clarify, two macros in the lz4hc.c, LZ4HC_DEFAULT_COMPRESSIONLEVEL and MAX_COMPRESSION_LEVEL, are defined as 8 and 16 respectively, but when using these to determine the maximum search attempts, these two macros are used directly, while the level supplied by the user is first subtracted by one. So I wrote 8+1 and 16+1 in LZ4Constants.java.

@DariusSki
Copy link

I'd really love to see this merged into main :)

@@ -152,13 +158,17 @@ public static LZ4Factory fastestInstance() {
private final LZ4Compressor highCompressor;
private final LZ4FastDecompressor fastDecompressor;
private final LZ4SafeDecompressor safeDecompressor;
private final Constructor<? extends LZ4Compressor> highConstructor;
private final HashMap<Integer, LZ4Compressor> highCompressors = new HashMap<Integer, LZ4Compressor>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of creating them on demand and then caching them, maybe we should create them all up-front and cache them in an array where the index is the compression level?

@jpountz
Copy link
Collaborator

jpountz commented Sep 30, 2014

I just left one comment about the caching of instances but other than that it looks good to me!

@linnaea
Copy link
Contributor Author

linnaea commented Sep 30, 2014

I did some benchmark and it turns out that creating them on demand and then cache the result is slightly faster than creating all of them when constructing.

The result on my machine (E3-1230v2 with 20GB RAM, running Java 8 x84 on Windows 7) is:

On demand cache with HashMap: 2857 ms

On demand cache with AtomicReferenceArray(linnaea/lz4-java@4e77dbe): 2733 ms

Creating all of them beforehand(linnaea/lz4-java@4cb7243): 3441 ms

@jpountz
Copy link
Collaborator

jpountz commented Oct 2, 2014

I am not sure to understand what you are measuring here? Is it the time it takes to initialize everything? If so I think it's ok as it is a one-time cost? Something I like about this last option is that if there are issues with instantiating the compressor with some compression levels (I'd rather be careful with reflection), it would fail immediately as opposed as when the compressor is requested.

Create all compressors up-front.
@linnaea
Copy link
Contributor Author

linnaea commented Oct 2, 2014

The benchmarking code calls highCompressor with various compression level 100,000 times and measures the time taken to complete.

It may be better to make sure the calls never fail anyway.

@jpountz
Copy link
Collaborator

jpountz commented Oct 7, 2014

This looks good to me now, the only thing I would like to remove is the new LZ4HCCompressor abstract class in order to keep the API minimal. What do you think?

@linnaea
Copy link
Contributor Author

linnaea commented Oct 10, 2014

LZ4HCCompressor removed.

It was there so that one can get the compression level actually in use and probably display it to the user. Now that the call to highCompressor is now guaranteed to never fail, it's probably redundant.

@jpountz
Copy link
Collaborator

jpountz commented Oct 12, 2014

I'm trying to merge the change but am getting some test failures. Looking into it...

@jpountz jpountz merged commit a619374 into lz4:master Oct 12, 2014
@jpountz
Copy link
Collaborator

jpountz commented Oct 12, 2014

Found it, all is good now. Thanks @linnaea !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants