From cf1a2b949716b48113fa27494d57e9f5b3c613a1 Mon Sep 17 00:00:00 2001 From: Uttam Pawar Date: Thu, 12 Jun 2025 14:11:22 -0700 Subject: [PATCH] Improve throughput performance at compression level 9 by adjusting M_MMAP_THRESHOLD value. This patch specifically addresses issue observed at level 9, it doesn't have adverse impact at other levels. Following are the performance numbers for various inputs on latest Xeon server. Runtime 10 seconds Compression level 9 MiB/sec Imp Ratio Input Input-sz compressed-sz Default Opt Opt/Default x 1 5 0.27 3.62 13.41 xyzzy 5 9 0.61 1.65 2.70 xyzzy.compressed 9 13 0.64 2.58 4.03 64x 64 10 8.73 27.13 3.11 alice29.txt 152,089 51,054 11.36 27.73 2.44 alice29.txt.compressed 50,096 50,100 7.13 6.91 0.97 asyoulik.txt 125,179 46,694 9.85 27.16 2.76 asyoulik.txt.compressed 45,687 45,691 6.68 6.61 0.99 backward65536 65,792 19 2,359.99 4371.97 1.85 bb.binast 12,356,697 5,412,654 5.89 5.89 1.00 compressed_file 50,096 50,100 7.13 7.01 0.98 compressed_file.compressed 50,100 50,104 7.13 7.09 0.99 compressed_repeated 144,224 50,443 15.90 168.83 10.62 compressed_repeated.compressed 50,299 50,303 6.90 6.73 0.98 cp1251-utf16le 1,554 660 1.32 38.11 28.87 empty.compressed.17 65,538 17 2,794.64 4558.76 1.63 empty.compressed.18 196,610 22 4,568.71 6190.96 1.36 lcet10.txt 426,754 127,437 17.17 26.17 1.52 lcet10.txt.compressed 124,719 124,724 14.65 14.37 0.98 mapsdatazrh 285,886 166,978 16.09 30.18 1.88 mapsdatazrh.compressed 161,743 161,748 18.12 18 0.99 monkey 843 423 1.50 32.68 21.79 plrabn12.txt 481,861 177,362 14.75 20.08 1.36 plrabn12.txt.compressed 174,771 174,776 19.93 19.78 0.99 quickfox_repeated 176,128 51 2,202.14 5649.04 2.57 random_chunks 2,704 1,906 2.25 44.59 19.82 random_org_10k.bin 10,000 10,004 3.25 125.47 38.61 random_org_10k.bin.compressed 10,004 10,008 3.20 119.01 37.19 ukkonooa 119 71 1.48 13.6 9.19 index.html (from cloudfare) 29,329 7,476 4.76 45.24 9.50 --- c/enc/encode.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/c/enc/encode.c b/c/enc/encode.c index fb2c0ce2b..f1e8d20a7 100644 --- a/c/enc/encode.c +++ b/c/enc/encode.c @@ -12,6 +12,7 @@ #include /* free, malloc */ #include /* memcpy, memset */ +#include /* M_MMAP_THRESHOLD */ #include "../common/constants.h" #include "../common/context.h" @@ -754,6 +755,12 @@ BrotliEncoderState* BrotliEncoderCreateInstance( /* BROTLI_DUMP(); */ return 0; } + + /* Overrides default dynamic mmap threshold set by glibc. */ + if (mallopt(M_MMAP_THRESHOLD, 34603008) == 0) { + BROTLI_LOG("Ignoring MMAP_THRESHOLD setting\n"); + } + BrotliInitMemoryManager( &state->memory_manager_, alloc_func, free_func, opaque); BrotliEncoderInitState(state);