h2o: Do not initialize the mime types map at startup
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 14 Jun 2023 13:19:58 +0000 (15:19 +0200)
committerRosen Penev <rosenp@gmail.com>
Thu, 22 Jun 2023 18:36:50 +0000 (21:36 +0300)
The map takes a fair amount of memory and the only consumer of this
library, dnsdist, does not need it.

Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
libs/h2o/patches/700-no-mime-map.patch [new file with mode: 0644]

diff --git a/libs/h2o/patches/700-no-mime-map.patch b/libs/h2o/patches/700-no-mime-map.patch
new file mode 100644 (file)
index 0000000..7fccfa6
--- /dev/null
@@ -0,0 +1,73 @@
+--- a/lib/core/config.c
++++ b/lib/core/config.c
+@@ -1,3 +1,4 @@
++
+ /*
+  * Copyright (c) 2014-2016 DeNA Co., Ltd.
+  *
+@@ -37,7 +38,9 @@ static h2o_hostconf_t *create_hostconf(h
+     hostconf->http2.push_preload = 1; /* enabled by default */
+     h2o_config_init_pathconf(&hostconf->fallback_path, globalconf, NULL, globalconf->mimemap);
+     hostconf->mimemap = globalconf->mimemap;
+-    h2o_mem_addref_shared(hostconf->mimemap);
++    if (hostconf->mimemap) {
++      h2o_mem_addref_shared(hostconf->mimemap);
++    }
+     return hostconf;
+ }
+@@ -54,7 +57,9 @@ static void destroy_hostconf(h2o_hostcon
+     }
+     free(hostconf->paths.entries);
+     h2o_config_dispose_pathconf(&hostconf->fallback_path);
+-    h2o_mem_release_shared(hostconf->mimemap);
++    if (hostconf->mimemap) {
++      h2o_mem_release_shared(hostconf->mimemap);
++    }
+     free(hostconf);
+ }
+@@ -136,8 +141,10 @@ void h2o_config_init_pathconf(h2o_pathco
+     h2o_chunked_register(pathconf);
+     if (path != NULL)
+         pathconf->path = h2o_strdup(NULL, path, SIZE_MAX);
+-    h2o_mem_addref_shared(mimemap);
+-    pathconf->mimemap = mimemap;
++    if (mimemap) {
++      h2o_mem_addref_shared(mimemap);
++      pathconf->mimemap = mimemap;
++    }
+     pathconf->error_log.emit_request_errors = 1;
+ }
+@@ -190,7 +197,7 @@ void h2o_config_init(h2o_globalconf_t *c
+     config->http2.latency_optimization.max_additional_delay = 10;
+     config->http2.latency_optimization.max_cwnd = 65535;
+     config->http2.callbacks = H2O_HTTP2_CALLBACKS;
+-    config->mimemap = h2o_mimemap_create();
++    // config->mimemap = h2o_mimemap_create();
+     h2o_configurator__init_core(config);
+ }
+@@ -279,7 +286,9 @@ void h2o_config_dispose(h2o_globalconf_t
+     }
+     free(config->hosts);
+-    h2o_mem_release_shared(config->mimemap);
++    if (config->mimemap) {
++      h2o_mem_release_shared(config->mimemap);
++    }
+     h2o_configurator__dispose_configurators(config);
+ }
+--- a/lib/core/request.c
++++ b/lib/core/request.c
+@@ -486,7 +486,7 @@ void h2o_req_fill_mime_attributes(h2o_re
+     ssize_t content_type_index;
+     h2o_mimemap_type_t *mime;
+-    if (req->res.mime_attr != NULL)
++    if (req->res.mime_attr != NULL || req->pathconf->mimemap == NULL)
+         return;
+     if ((content_type_index = h2o_find_header(&req->res.headers, H2O_TOKEN_CONTENT_TYPE, -1)) != -1 &&