mirror of
https://github.com/google/brotli.git
synced 2026-07-08 17:56:58 +00:00
Functions to calculate approximate memory usage needed for compression and decompression #122
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @GregSlazinski on GitHub (Jul 3, 2016).
Is it possible to provide such functions?
Such as :
int64 BrotliCompressionMemUsage(int quality, int lgwin, BrotliEncoderMode mode);
int64 BrotliDecompressionMemUsage(int quality, int lgwin, BrotliEncoderMode mode);
In my program, I use multi-threaded compression, by executing multiple compressors on multiple threads.
However I limit the number of simultaneous threads by the number of available memory .
For example if system has 4 GB of RAM.
And each call to compress function would require 1 GB of memory usage.
Based on that info I would know that I can create up to 4 threads.
However I was unable to find any information about memory usage for compressing and decompressing with Brotli.
Thank you
@eustas commented on GitHub (Jul 28, 2016):
Hello. For decompressor it is easy. For compressor we have only rough estimates (there are about 90 places where memory is allocated).
Going to add method for decompressor soon and for compressor after some code combing...
@eustas commented on GitHub (Jun 9, 2017):
For decompressor the worst case is 2.6MiB + 1.5 * ringbuffer size. Soon an API for calculating ringbuffer size from the first byte will appear + ability to remove 1.5x multiplier.
As for encoder, we still need more time to build the right model.
@Pro100AlexHell commented on GitHub (Dec 25, 2017):
Hello! Could you please answer:
@eustas commented on GitHub (Oct 22, 2018):
@Pro100AlexHell commented on GitHub (Oct 23, 2018):
@eustas commented on GitHub (Oct 24, 2018):
Both Firefox and Chrome use reference (this) decoder.
Decoder does very few allocations, IIRC less than 7. Chrome uses rather effective memory manager (TCMalloc). Combine those facts, and memory reuse would never be a problem.
Can't share exact stats, but in 50+% of cases memory usage is slightly above 32K; in the majority of cases memory usage is below 0.5MiB. That highly depends on the size of the file; to be more precise, it depends on "window size"; Huffman tables together with other all the other overheads is just a tiny fraction of used memory.
@eustas commented on GitHub (Jan 6, 2023):
BrotliEncoderEstimatePeakMemoryUsagehas been added.As I've mentioned before - for decoder it is easier, but impossible without knowing the first 2 bytes of input...