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

Best values for lgwin and lgblock? #244

Closed
MacGritsch opened this issue Oct 28, 2015 · 8 comments
Closed

Best values for lgwin and lgblock? #244

MacGritsch opened this issue Oct 28, 2015 · 8 comments

Comments

@MacGritsch
Copy link

Hi,

how can I calculate the best values for lgwin and lgblock?
If I use the default values to compress a buffer with only a few KB, brotli allocates 8 MB for the ringbuffer.
I think this makes no sense, so wouldnt it be a good idea to calculate the two values depending on the size of the data that should be compressed?

thx

@MacGritsch
Copy link
Author

Does this solution make sense?

params.lgwin = 22;

for (int i = 10; i < 22; i++)
{
    if (encodedSize <= (1 << i))
    {
        params.lgwin = i;

        break;
    }
}

@jyrkialakuijala
Copy link
Collaborator

lgwin can be up to 24 in brotli, but the maximum you want to use depends on the capabilities of the client running the decoder. For the mobile web use it might be wise to avoid the levels 23 and 24, and possibly smart to stay at 19.

@MacGritsch
Copy link
Author

lgwin of 24 bit means more than 50 MB of memory usage.

the question is still active: does my code make sense, and wouldnt it be a good idea to add this functionality functionality to the param-class?

@eustas
Copy link
Collaborator

eustas commented Nov 6, 2015

This could easily be added to BrotliCompressBuffer method, but impossible for streaming versions (as the data size is unknown).

So, if we add the logic that reduces window size to BrotliCompressBuffer, will it work for you?

@MacGritsch
Copy link
Author

Why not add the size as an optional parameter to BrotliParams() constructor?

@eustas
Copy link
Collaborator

eustas commented Nov 6, 2015

It would look a little bit confusing and redundant - lgwin and lgblock already specify the expected use-case. Probably it can be done with some helper function that adjusts BrotliParams given the expected input size...

@sg77
Copy link

sg77 commented Mar 16, 2016

Yes, that would be good.
At least some formula on the documentation. I'm interested in knowing how can I limit the amount of memory used while decoding by tunning the encoding parameters,

@eustas
Copy link
Collaborator

eustas commented Jun 9, 2017

Basic formulae is max(24, min(10, log2(size)+0.5)), if memory itself is not a problem.
If memory is a limited resource, then lgwin should be lowered a bit, but for higher qualities, hashers might take more memory than ring-buffer, so cutting lgwin won't give a big win.

@eustas eustas closed this as completed Jun 9, 2017
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

No branches or pull requests

4 participants