Skip to content

Commit 2a5a088

Browse files
eustascopybara-github
authored andcommitted
more tuning for BROTLI_EXPERIMENTAL + clean-on-oom
PiperOrigin-RevId: 558771745
1 parent feb6d8b commit 2a5a088

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

c/enc/encode.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,15 @@ BROTLI_BOOL BrotliEncoderAttachPreparedDictionary(BrotliEncoderState* state,
18361836
size_t BrotliEncoderEstimatePeakMemoryUsage(int quality, int lgwin,
18371837
size_t input_size) {
18381838
BrotliEncoderParams params;
1839+
size_t memory_manager_slots = 0;
1840+
size_t memory_manager_size = 0;
1841+
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
1842+
memory_manager_slots = 256;
1843+
#if defined(BROTLI_EXPERIMENTAL)
1844+
memory_manager_slots = 32768;
1845+
#endif /* BROTLI_EXPERIMENTAL */
1846+
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
1847+
memory_manager_size = memory_manager_slots * sizeof(void*);
18391848
BrotliEncoderInitParams(&params);
18401849
params.quality = quality;
18411850
params.lgwin = lgwin;
@@ -1892,7 +1901,7 @@ size_t BrotliEncoderEstimatePeakMemoryUsage(int quality, int lgwin,
18921901
command_histograms * sizeof(HistogramCommand) +
18931902
distance_histograms * sizeof(HistogramDistance);
18941903
}
1895-
return (ringbuffer_size +
1904+
return (memory_manager_size + ringbuffer_size +
18961905
hash_size[0] + hash_size[1] + hash_size[2] + hash_size[3] +
18971906
cmdbuf_size +
18981907
outbuf_size +

c/enc/memory.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
extern "C" {
2121
#endif
2222

23-
/* TODO(eustas): fine-tune for "many slots" case */
24-
#define MAX_NEW_ALLOCATED 64
25-
#define MAX_NEW_FREED 64
26-
#define MAX_PERM_ALLOCATED \
27-
(BROTLI_ENCODER_MEMORY_MANAGER_SLOTS - MAX_NEW_ALLOCATED - MAX_NEW_FREED)
23+
#define MAX_NEW_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
24+
#define MAX_NEW_FREED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
25+
#define MAX_PERM_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 1)
2826

2927
#define PERM_ALLOCATED_OFFSET 0
3028
#define NEW_ALLOCATED_OFFSET MAX_PERM_ALLOCATED

c/enc/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626

2727
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
2828
#if defined(BROTLI_EXPERIMENTAL)
29-
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 6144
29+
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 32768
3030
#else /* BROTLI_EXPERIMENTAL */
3131
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 256
3232
#endif /* BROTLI_EXPERIMENTAL */

0 commit comments

Comments
 (0)