Skip to content
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 .push loop instead of spread operator #20108

Merged
merged 3 commits into from
Aug 9, 2023

Conversation

marcosc90
Copy link
Contributor

This PR slightly improves performance of Header iterator by using .concat instead of spread operator.

This patch

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 iterator       1.49 µs/iter     669,569.7     (1.48 µs … 1.56 µs)    1.5 µs   1.56 µs   1.56 µs

Main

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 iterator       1.62 µs/iter     617,624.9     (1.59 µs … 1.66 µs)   1.63 µs   1.66 µs   1.66 µs
const headers = new Headers({
  "Content-Type": "application/json",
  "Date": "Wed, 09 Aug 2023 11:37:57 GMT",
});

Deno.bench("Headers iterator", () => {
  const i = [...headers];
});

@bartlomieju
Copy link
Member

@marcosc90 very nice, how do the results look like if you increase number of headers to 8-10?

@marcosc90
Copy link
Contributor Author

@bartlomieju it's always faster, here's the bench for 8 headers.

const headers = new Headers({
  "Content-Type": "application/json",
  "Date": "Wed, 09 Aug 2023 11:37:57 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"
});

This patch

benchmark             time (avg)        iter/s             (min … max)       p75       p99      p995
---------------------------------------------------------------------- -----------------------------
Headers iterator      10.59 µs/iter      94,446.5   (9.64 µs … 107.35 µs)  10.39 µs  14.51 µs  49.75 µs

Main

benchmark             time (avg)        iter/s             (min … max)       p75       p99      p995
---------------------------------------------------------------------- -----------------------------
Headers iterator      12.03 µs/iter      83,097.9  (10.97 µs … 243.54 µs)  11.76 µs  16.97 µs  53.33 µs

@marcosc90
Copy link
Contributor Author

@bartlomieju got much better results with the latest push.

2 headers

benchmark             time (avg)        iter/s             (min … max)       p75       p99      p995
---------------------------------------------------------------------- -----------------------------
Headers iterator        1.3 µs/iter     771,516.2     (1.27 µs … 1.32 µs)    1.3 µs   1.32 µs   1.32 µs

8 headers

benchmark             time (avg)        iter/s             (min … max)       p75       p99      p995
---------------------------------------------------------------------- -----------------------------
Headers iterator       9.78 µs/iter     102,259.9    (9.13 µs … 97.81 µs)   9.57 µs  12.61 µs   50.1 µ

@marcosc90 marcosc90 changed the title perf(ext/headers): use concat instead of spread operator perf(ext/headers): use .push loop instead of spread operator Aug 9, 2023
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic! Thanks

@lucacasonato lucacasonato merged commit 414274b into denoland:main Aug 9, 2023
13 checks passed
@marcosc90 marcosc90 deleted the perf-headers-iter branch September 16, 2023 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants