more tuning for BROTLI_EXPERIMENTAL + clean-on-oom

PiperOrigin-RevId: 558771745
This commit is contained in:
Evgenii Kliuchnikov 2023-08-21 06:35:47 -07:00 committed by Copybara-Service
parent feb6d8bc80
commit 2a5a088b03
3 changed files with 14 additions and 7 deletions

View File

@ -1836,6 +1836,15 @@ BROTLI_BOOL BrotliEncoderAttachPreparedDictionary(BrotliEncoderState* state,
size_t BrotliEncoderEstimatePeakMemoryUsage(int quality, int lgwin,
size_t input_size) {
BrotliEncoderParams params;
size_t memory_manager_slots = 0;
size_t memory_manager_size = 0;
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
memory_manager_slots = 256;
#if defined(BROTLI_EXPERIMENTAL)
memory_manager_slots = 32768;
#endif /* BROTLI_EXPERIMENTAL */
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
memory_manager_size = memory_manager_slots * sizeof(void*);
BrotliEncoderInitParams(&params);
params.quality = quality;
params.lgwin = lgwin;
@ -1892,7 +1901,7 @@ size_t BrotliEncoderEstimatePeakMemoryUsage(int quality, int lgwin,
command_histograms * sizeof(HistogramCommand) +
distance_histograms * sizeof(HistogramDistance);
}
return (ringbuffer_size +
return (memory_manager_size + ringbuffer_size +
hash_size[0] + hash_size[1] + hash_size[2] + hash_size[3] +
cmdbuf_size +
outbuf_size +

View File

@ -20,11 +20,9 @@
extern "C" {
#endif
/* TODO(eustas): fine-tune for "many slots" case */
#define MAX_NEW_ALLOCATED 64
#define MAX_NEW_FREED 64
#define MAX_PERM_ALLOCATED \
(BROTLI_ENCODER_MEMORY_MANAGER_SLOTS - MAX_NEW_ALLOCATED - MAX_NEW_FREED)
#define MAX_NEW_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
#define MAX_NEW_FREED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
#define MAX_PERM_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 1)
#define PERM_ALLOCATED_OFFSET 0
#define NEW_ALLOCATED_OFFSET MAX_PERM_ALLOCATED

View File

@ -26,7 +26,7 @@ extern "C" {
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
#if defined(BROTLI_EXPERIMENTAL)
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 6144
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 32768
#else /* BROTLI_EXPERIMENTAL */
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 256
#endif /* BROTLI_EXPERIMENTAL */