diff options
author | Evgenii Kliuchnikov <eustas@google.com> | 2023-08-21 06:35:47 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-08-21 06:36:24 -0700 |
commit | 2a5a088b03ba5fd3aab4f34338c84e2c61d82c49 (patch) | |
tree | 349640a42e65651e48bbd3af91ea9e86ca50dd4f | |
parent | feb6d8bc80d82dc2123bf8e8200dbc3af42f9bc2 (diff) | |
download | brotli-2a5a088b03ba5fd3aab4f34338c84e2c61d82c49.zip brotli-2a5a088b03ba5fd3aab4f34338c84e2c61d82c49.tar.gz brotli-2a5a088b03ba5fd3aab4f34338c84e2c61d82c49.tar.bz2 |
more tuning for BROTLI_EXPERIMENTAL + clean-on-oomv1.1.0rc
PiperOrigin-RevId: 558771745
-rw-r--r-- | c/enc/encode.c | 11 | ||||
-rw-r--r-- | c/enc/memory.c | 8 | ||||
-rw-r--r-- | c/enc/memory.h | 2 |
3 files changed, 14 insertions, 7 deletions
diff --git a/c/enc/encode.c b/c/enc/encode.c index 81ea40e..6ce8edd 100644 --- a/c/enc/encode.c +++ b/c/enc/encode.c @@ -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(¶ms); 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 + diff --git a/c/enc/memory.c b/c/enc/memory.c index 8811821..bb5e364 100644 --- a/c/enc/memory.c +++ b/c/enc/memory.c @@ -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 diff --git a/c/enc/memory.h b/c/enc/memory.h index 9dbed55..a958fdd 100644 --- a/c/enc/memory.h +++ b/c/enc/memory.h @@ -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 */ |