lib/libz/0001-Port-inflate-dynamic-table-size-optimization.patch
$ cat 0001-Port-inflate-dynamic-table-size-optimization.patch
From c0f270495c22911bcfb38b66166e3cc493f00fb7 Mon Sep 17 00:00:00 2001
From: Felix Hanau <felix@cloudflare.com>
Date: Sun, 12 Feb 2023 21:15:38 -0500
Subject: [PATCH 1/4] Port inflate dynamic table size optimization

Increase the size of the dynamic tables used for huffman decoding, which
requires slightly more memory but leads to performance improvements
across platforms.
Based on Dougall Johnson's inflate improvements via Adenilson
Cavalcanti's patch for the Chromium zlib fork.
See https://chromium-review.googlesource.com/c/chromium/src/+/3888219
for details.
---
 infback.c  |  6 +++---
 inflate.c  |  6 +++---
 inftrees.h | 10 +++++-----
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/infback.c b/infback.c
index 9b1d776..f0a5905 100644
--- a/infback.c
+++ b/infback.c
@@ -401,11 +401,11 @@ int ZEXPORT inflateBack(z_stream *strm,
             }
 
             /* build code tables -- note: do not change the lenbits or distbits
-               values here (9 and 6) without reading the comments in inftrees.h
+               values here (10 and 9) without reading the comments in inftrees.h
                concerning the ENOUGH constants, which depend on those values */
             state->next = state->codes;
             state->lencode = (const code *)(state->next);
-            state->lenbits = 9;
+            state->lenbits = 10;
             ret = inflate_table(LENS, state->lens, state->nlen, &state->next,
                                 &state->lenbits, state->work);
             if (ret) {
@@ -414,7 +414,7 @@ int ZEXPORT inflateBack(z_stream *strm,
                 break;
             }
             state->distcode = (const code *)(state->next);
-            state->distbits = 6;
+            state->distbits = 9;
             ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
                             &state->next, &state->distbits, state->work);
             if (ret) {
diff --git a/inflate.c b/inflate.c
index 9229ab8..33b66c8 100644
--- a/inflate.c
+++ b/inflate.c
@@ -849,11 +849,11 @@ int ZEXPORT inflate(z_stream *strm,
             }
 
             /* build code tables -- note: do not change the lenbits or distbits
-               values here (9 and 6) without reading the comments in inftrees.h
+               values here (10 and 9) without reading the comments in inftrees.h
                concerning the ENOUGH constants, which depend on those values */
             state->next = state->codes;
             state->lencode = (const code *)(state->next);
-            state->lenbits = 9;
+            state->lenbits = 10;
             ret = inflate_table(LENS, state->lens, state->nlen, &state->next,
                                 &state->lenbits, state->work);
             if (ret) {
@@ -862,7 +862,7 @@ int ZEXPORT inflate(z_stream *strm,
                 break;
             }
             state->distcode = (const code *)(state->next);
-            state->distbits = 6;
+            state->distbits = 9;
             ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
                                 &state->next, &state->distbits, state->work);
             if (ret) {
diff --git a/inftrees.h b/inftrees.h
index cf54ec1..c69532e 100644
--- a/inftrees.h
+++ b/inftrees.h
@@ -36,17 +36,17 @@ typedef struct {
  */
 
 /* Maximum size of the dynamic table.  The maximum number of code structures is
-   1444, which is the sum of 852 for literal/length codes and 592 for distance
+   1924, which is the sum of 1332 for literal/length codes and 592 for distance
    codes.  These values were found by exhaustive searches using the program
    examples/enough.c found in the zlib distribtution.  The arguments to that
    program are the number of symbols, the initial root table size, and the
-   maximum bit length of a code.  "enough 286 9 15" for literal/length codes
-   returns returns 852, and "enough 30 6 15" for distance codes returns 592.
-   The initial root table size (9 or 6) is found in the fifth argument of the
+   maximum bit length of a code.  "enough 286 10 15" for literal/length codes
+   returns returns 1332, and "enough 30 9 15" for distance codes returns 592.
+   The initial root table size (10 or 9) is found in the fifth argument of the
    inflate_table() calls in inflate.c and infback.c.  If the root table size is
    changed, then these maximum sizes would be need to be recalculated and
    updated. */
-#define ENOUGH_LENS 852
+#define ENOUGH_LENS 1332
 #define ENOUGH_DISTS 592
 #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
 
-- 
2.55.0