summaryrefslogtreecommitdiff
path: root/ext/fetch/20_headers.js
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2023-08-15 16:59:35 +0200
committerGitHub <noreply@github.com>2023-08-15 16:59:35 +0200
commitddbb5fdfb034517f200e298c1a5de8aa03b5e5e5 (patch)
tree80edc986c334b8eef3f212730d30107452650615 /ext/fetch/20_headers.js
parent0fc31d9d657b4ccf24099803d5321182f08f710c (diff)
perf(ext/node): optimize http headers (#20163)
This PR optimizes Node's `IncomingMessageForServer.headers` by replacing `Object.fromEntries()` with a loop and `headers.entries` with `headersEntries` which returns the internal array directly instead of an iterator ## Benchmarks Using `wrk` with 5 headers ``` wrk -d 10s --latency -H "X-Deno: true" -H "Accept: application/json" -H "X-Foo: bar" -H "User-Agent: wrk" -H "Accept-Encoding: gzip, br" http://127.0.0.1:3000 ``` **this PR** ``` Running 10s test @ http://127.0.0.1:3000 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 167.53us 136.89us 2.75ms 97.33% Req/Sec 31.98k 1.38k 36.39k 70.30% Latency Distribution 50% 134.00us 75% 191.00us 90% 234.00us 99% 544.00us 642548 requests in 10.10s, 45.96MB read Requests/sec: 63620.36 Transfer/sec: 4.55MB ``` **main** ``` Running 10s test @ http://127.0.0.1:3000 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 181.31us 132.54us 3.79ms 97.13% Req/Sec 29.21k 1.45k 32.93k 79.21% Latency Distribution 50% 148.00us 75% 198.00us 90% 261.00us 99% 545.00us 586939 requests in 10.10s, 41.98MB read Requests/sec: 58114.01 Transfer/sec: 4.16MB ``` ```js import express from "npm:express"; const app = express(); app.get("/", function (req, res) { req.headers; res.end(); }); app.listen(3000); ```
Diffstat (limited to 'ext/fetch/20_headers.js')
-rw-r--r--ext/fetch/20_headers.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js
index 4e1729e01..39127b1ec 100644
--- a/ext/fetch/20_headers.js
+++ b/ext/fetch/20_headers.js
@@ -508,6 +508,14 @@ function guardFromHeaders(headers) {
return headers[_guard];
}
+/**
+ * @param {Headers} headers
+ * @returns {[string, string][]}
+ */
+function headersEntries(headers) {
+ return headers[_iterableHeaders];
+}
+
export {
fillHeaders,
getDecodeSplitHeader,
@@ -515,5 +523,6 @@ export {
guardFromHeaders,
headerListFromHeaders,
Headers,
+ headersEntries,
headersFromHeaderList,
};