-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(ext/headers): use regex.test instead of .exec #20125
Conversation
Correct benchmarks, since I was using an outdated build without the recent perf additions. main
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If you want to try out an experiment we never landed, some testing we did a few months back showed that bit-testing is the absolute fastest way to do this I believe that this is the code we used for the experiment:
|
I'll do a bit of testing with that @mmastrac Regarding this PR, I noticed that @bartlomieju changed Someone want to bench this and post results? All my benches result in Here are some random regex bench (Dell XPS - Ubuntu 22.04)
|
As @lino-levan said on the other PR "The V8 engine is a whimsical place, seemingly random changes can have surprising differences in performance." Are you using |
I'm going to close for now, and do some further benching when I have some extra time. |
@marcosc90 I think we land this PR as is, we can run internal benches tomorrow to see if there's visible improvement. |
@bartlomieju sounds good to me. I'm also going through all regex being used in headers/response to see if they can be optimized a bit. |
Great to hear that as these regexes are showing up in the flamegraphs we plot. If you want to take a deeper look into what's going on when benching HTTP server I highly recommend using |
Merged this one as is -- thanks for all the perf fixes! |
This PR improves the performance of `Headers.get` by using `Regex.test` instead of `.exec`. Also replaced the `Map` used for caching with an object which is a bit faster **This patch** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------- ----------------------------- Headers.get 124.71 ns/iter 8,018,687.3 (115.11 ns … 265.66 ns) 126.05 ns 136.12 ns 142.37 ns ``` **1.36.1** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.0 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------- ----------------------------- Headers.get 218.91 ns/iter 4,568,172.3 (165.37 ns … 264.44 ns) 241.62 ns 260.94 ns 262.67 ns ``` ```js const headers = new Headers({ "Content-Type": "application/json", "Date": "Thu, 10 Aug 2023 07:45:10 GMT", "X-Deno": "Deno", "Powered-By": "Deno", "Content-Encoding": "gzip", "Set-Cookie": "__Secure-ID=123; Secure; Domain=example.com", "Content-Length": "150", "Vary": "Accept-Encoding, Accept, X-Requested-With", }); Deno.bench("Headers.get", () => { headers.get("x-deno"); }); ```
This PR improves the performance of `Headers.get` by using `Regex.test` instead of `.exec`. Also replaced the `Map` used for caching with an object which is a bit faster **This patch** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------- ----------------------------- Headers.get 124.71 ns/iter 8,018,687.3 (115.11 ns … 265.66 ns) 126.05 ns 136.12 ns 142.37 ns ``` **1.36.1** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.0 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------- ----------------------------- Headers.get 218.91 ns/iter 4,568,172.3 (165.37 ns … 264.44 ns) 241.62 ns 260.94 ns 262.67 ns ``` ```js const headers = new Headers({ "Content-Type": "application/json", "Date": "Thu, 10 Aug 2023 07:45:10 GMT", "X-Deno": "Deno", "Powered-By": "Deno", "Content-Encoding": "gzip", "Set-Cookie": "__Secure-ID=123; Secure; Domain=example.com", "Content-Length": "150", "Vary": "Accept-Encoding, Accept, X-Requested-With", }); Deno.bench("Headers.get", () => { headers.get("x-deno"); }); ```
This PR improves the performance of
Headers.get
by usingRegex.test
instead of.exec
. Also replaced theMap
used for caching with an object which is a bit fasterThis patch
1.36.1