From dabce813e064b7b3a2197cb327bde00e7b403688 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 13 Apr 2021 02:46:33 +0200 Subject: perf: lazy header instantiation for HTTP requests (#10150) This commit introduces a performance optimization for the native HTTP server. From my testing it is about 2-6% faster than `main`. Request headers in the HTTP servers are now lazilly instatated when they are accessed, rather than being preemptively wrapped in the `Headers` class. --- runtime/js/40_http.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/js') diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js index 4a2dcdf4a..18ead84c3 100644 --- a/runtime/js/40_http.js +++ b/runtime/js/40_http.js @@ -2,7 +2,7 @@ "use strict"; ((window) => { - const { Request, dontValidateUrl, fastBody, Response } = + const { Request, dontValidateUrl, lazyHeaders, fastBody, Response } = window.__bootstrap.fetch; const { Headers } = window.__bootstrap.headers; const errors = window.__bootstrap.errors.errors; @@ -61,8 +61,9 @@ const request = new Request(url, { body, method, - headers: new Headers(headersList), + headers: headersList, [dontValidateUrl]: true, + [lazyHeaders]: true, }); const respondWith = createRespondWith(responseSenderRid, this.#rid); -- cgit v1.2.3