Best values for lgwin and lgblock? #65

Closed
opened 2026-01-29 20:30:51 +00:00 by claunia · 8 comments
Owner

Originally created by @MacGritsch on GitHub (Oct 28, 2015).

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

Originally created by @MacGritsch on GitHub (Oct 28, 2015). 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
Author
Owner

@MacGritsch commented on GitHub (Oct 28, 2015):

Does this solution make sense?

params.lgwin = 22;

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

        break;
    }
}
@MacGritsch commented on GitHub (Oct 28, 2015): Does this solution make sense? ``` params.lgwin = 22; for (int i = 10; i < 22; i++) { if (encodedSize <= (1 << i)) { params.lgwin = i; break; } } ```
Author
Owner

@jyrkialakuijala commented on GitHub (Oct 31, 2015):

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.

@jyrkialakuijala commented on GitHub (Oct 31, 2015): 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.
Author
Owner

@MacGritsch commented on GitHub (Oct 31, 2015):

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?

@MacGritsch commented on GitHub (Oct 31, 2015): 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?
Author
Owner

@eustas commented on GitHub (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?

@eustas commented on GitHub (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?
Author
Owner

@MacGritsch commented on GitHub (Nov 6, 2015):

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

@MacGritsch commented on GitHub (Nov 6, 2015): Why not add the size as an optional parameter to BrotliParams() constructor?
Author
Owner

@eustas commented on GitHub (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...

@eustas commented on GitHub (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...
Author
Owner

@sg77 commented on GitHub (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,

@sg77 commented on GitHub (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,
Author
Owner

@eustas commented on GitHub (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 commented on GitHub (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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#65