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: only call removeHeader when needed #244

Merged
merged 2 commits into from
Aug 2, 2023
Merged

Conversation

gurgunday
Copy link
Member

@gurgunday gurgunday commented Aug 1, 2023

95% of the time, the header will not be defined when cookies are set, so there is no need to call removeHeader unless needed

Also, the setCookies function itself now resets the Map, which makes it easier to reason about what's going on

Median of 5 tests for 5 cookies

Old:

100 connections


┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬────────┐
│ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%  │ Avg     │ Stdev   │ Max    │
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼────────┤
│ Latency │ 1 ms │ 1 ms │ 2 ms  │ 3 ms │ 1.06 ms │ 0.72 ms │ 120 ms │
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴────────┘
┌───────────┬───────┬───────┬─────────┬───────┬──────────┬────────┬───────┐
│ Stat      │ 1%    │ 2.5%  │ 50%     │ 97.5% │ Avg      │ Stdev  │ Min   │
├───────────┼───────┼───────┼─────────┼───────┼──────────┼────────┼───────┤
│ Req/Sec   │ 60159 │ 60159 │ 65791   │ 66367 │ 64938.19 │ 1708.4 │ 60153 │
├───────────┼───────┼───────┼─────────┼───────┼──────────┼────────┼───────┤
│ Bytes/Sec │ 19 MB │ 19 MB │ 20.8 MB │ 21 MB │ 20.5 MB  │ 539 kB │ 19 MB │
└───────────┴───────┴───────┴─────────┴───────┴──────────┴────────┴───────┘

Req/Bytes counts sampled once per second.
# of samples: 11

714k requests in 11.01s, 226 MB read

New:

100 connections


┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬────────┐
│ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%  │ Avg     │ Stdev   │ Max    │
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼────────┤
│ Latency │ 1 ms │ 1 ms │ 2 ms  │ 2 ms │ 1.05 ms │ 0.66 ms │ 105 ms │
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg     │ Stdev  │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Req/Sec   │ 64575   │ 64575   │ 70783   │ 71359   │ 70160   │ 1838.4 │ 64549   │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Bytes/Sec │ 20.4 MB │ 20.4 MB │ 22.4 MB │ 22.6 MB │ 22.2 MB │ 585 kB │ 20.4 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴────────┴─────────┘

Req/Bytes counts sampled once per second.
# of samples: 11

772k requests in 11.01s, 244 MB read

Checklist

@gurgunday
Copy link
Member Author

@mcollina can you please make a patch release after this is merged?

54e9bdc fixes a case where you set more than 1 cookie after the hook runs

@Uzlopak Uzlopak merged commit 2165139 into fastify:master Aug 2, 2023
15 checks passed
@gurgunday gurgunday deleted the perf branch August 2, 2023 10:18
bodinsamuel referenced this pull request in specfy/specfy Aug 7, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@fastify/cookie](https://togithub.com/fastify/fastify-cookie) |
[`8.3.0` ->
`9.0.4`](https://renovatebot.com/diffs/npm/@fastify%2fcookie/8.3.0/9.0.4)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@fastify%2fcookie/9.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@fastify%2fcookie/9.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@fastify%2fcookie/8.3.0/9.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@fastify%2fcookie/8.3.0/9.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>fastify/fastify-cookie (@&#8203;fastify/cookie)</summary>

###
[`v9.0.4`](https://togithub.com/fastify/fastify-cookie/releases/tag/v9.0.4)

[Compare
Source](https://togithub.com/fastify/fastify-cookie/compare/v9.0.3...v9.0.4)

#### What's Changed

- Fix support for response that does not set a cookie by
[@&#8203;mcollina](https://togithub.com/mcollina) in
[https://github.com/fastify/fastify-cookie/pull/247](https://togithub.com/fastify/fastify-cookie/pull/247)

**Full Changelog**:
fastify/fastify-cookie@v9.0.3...v9.0.4

###
[`v9.0.3`](https://togithub.com/fastify/fastify-cookie/releases/tag/v9.0.3)

[Compare
Source](https://togithub.com/fastify/fastify-cookie/compare/v9.0.2...v9.0.3)

#### What's Changed

- Do not crash if responding from a previously-registered onRequest hook
by [@&#8203;mcollina](https://togithub.com/mcollina) in
[https://github.com/fastify/fastify-cookie/pull/245](https://togithub.com/fastify/fastify-cookie/pull/245)

**Full Changelog**:
fastify/fastify-cookie@v9.0.2...v9.0.3

###
[`v9.0.2`](https://togithub.com/fastify/fastify-cookie/releases/tag/v9.0.2)

[Compare
Source](https://togithub.com/fastify/fastify-cookie/compare/v9.0.1...v9.0.2)

#### What's Changed

- use for loop instead of for...of by
[@&#8203;gurgunday](https://togithub.com/gurgunday) in
[https://github.com/fastify/fastify-cookie/pull/239](https://togithub.com/fastify/fastify-cookie/pull/239)
- Check if onSend ran and keep resetting the map by
[@&#8203;gurgunday](https://togithub.com/gurgunday) in
[https://github.com/fastify/fastify-cookie/pull/242](https://togithub.com/fastify/fastify-cookie/pull/242)
- perf: only clear map when it's populated by
[@&#8203;gurgunday](https://togithub.com/gurgunday) in
[https://github.com/fastify/fastify-cookie/pull/243](https://togithub.com/fastify/fastify-cookie/pull/243)
- perf: only call removeHeader when needed by
[@&#8203;gurgunday](https://togithub.com/gurgunday) in
[https://github.com/fastify/fastify-cookie/pull/244](https://togithub.com/fastify/fastify-cookie/pull/244)

**Full Changelog**:
fastify/fastify-cookie@v9.0.1...v9.0.2

###
[`v9.0.1`](https://togithub.com/fastify/fastify-cookie/releases/tag/v9.0.1)

[Compare
Source](https://togithub.com/fastify/fastify-cookie/compare/v9.0.0...v9.0.1)

#### What's Changed

- Fix [@&#8203;fastify/session](https://togithub.com/fastify/session) by
[@&#8203;mcollina](https://togithub.com/mcollina) in
[https://github.com/fastify/fastify-cookie/pull/240](https://togithub.com/fastify/fastify-cookie/pull/240)

**Full Changelog**:
fastify/fastify-cookie@v9.0.0...v9.0.1

###
[`v9.0.0`](https://togithub.com/fastify/fastify-cookie/releases/tag/v9.0.0)

[Compare
Source](https://togithub.com/fastify/fastify-cookie/compare/v8.3.0...v9.0.0)

#### What's Changed

- fix(docs): msecs to seconds
([#&#8203;219](https://togithub.com/fastify/fastify-cookie/issues/219))
by [@&#8203;seia-soto](https://togithub.com/seia-soto) in
[https://github.com/fastify/fastify-cookie/pull/220](https://togithub.com/fastify/fastify-cookie/pull/220)
- chore(deps-dev): bump sinon from 14.0.2 to 15.0.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/fastify/fastify-cookie/pull/222](https://togithub.com/fastify/fastify-cookie/pull/222)
- chore(deps-dev): bump tsd from 0.24.1 to 0.25.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/fastify/fastify-cookie/pull/223](https://togithub.com/fastify/fastify-cookie/pull/223)
- chore(.gitignore): add clinic by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[https://github.com/fastify/fastify-cookie/pull/226](https://togithub.com/fastify/fastify-cookie/pull/226)
- chore(.gitignore): add bun lockfile by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[https://github.com/fastify/fastify-cookie/pull/228](https://togithub.com/fastify/fastify-cookie/pull/228)
- chore(deps-dev): bump tsd from 0.25.0 to 0.26.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/fastify/fastify-cookie/pull/229](https://togithub.com/fastify/fastify-cookie/pull/229)
- chore(deps-dev): bump tsd from 0.26.1 to 0.27.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/fastify/fastify-cookie/pull/230](https://togithub.com/fastify/fastify-cookie/pull/230)
- chore(deps-dev): bump tsd from 0.27.0 to 0.28.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/fastify/fastify-cookie/pull/231](https://togithub.com/fastify/fastify-cookie/pull/231)
- ci: only trigger on pushes to main branches by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[https://github.com/fastify/fastify-cookie/pull/232](https://togithub.com/fastify/fastify-cookie/pull/232)
- chore(deps-dev): bump
[@&#8203;types/node](https://togithub.com/types/node) from 18.16.5 to
20.1.0 by [@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/fastify/fastify-cookie/pull/233](https://togithub.com/fastify/fastify-cookie/pull/233)
- Fix typo from 'node' to 'none' in CookieSerializeOptions for sameSite
attribute by [@&#8203;Mihai-MCW](https://togithub.com/Mihai-MCW) in
[https://github.com/fastify/fastify-cookie/pull/236](https://togithub.com/fastify/fastify-cookie/pull/236)
- Don't send the `Set-Cookie` header multiple times for the same cookie
by [@&#8203;gurgunday](https://togithub.com/gurgunday) in
[https://github.com/fastify/fastify-cookie/pull/237](https://togithub.com/fastify/fastify-cookie/pull/237)

#### New Contributors

- [@&#8203;seia-soto](https://togithub.com/seia-soto) made their first
contribution in
[https://github.com/fastify/fastify-cookie/pull/220](https://togithub.com/fastify/fastify-cookie/pull/220)
- [@&#8203;Mihai-MCW](https://togithub.com/Mihai-MCW) made their first
contribution in
[https://github.com/fastify/fastify-cookie/pull/236](https://togithub.com/fastify/fastify-cookie/pull/236)
- [@&#8203;gurgunday](https://togithub.com/gurgunday) made their first
contribution in
[https://github.com/fastify/fastify-cookie/pull/237](https://togithub.com/fastify/fastify-cookie/pull/237)

**Full Changelog**:
fastify/fastify-cookie@v8.3.0...v9.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 4pm on friday,before 9am on
monday,every weekend" in timezone Europe/Paris, Automerge - At any time
(no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/specfy/specfy).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNy4xIiwidXBkYXRlZEluVmVyIjoiMzYuMjcuMSIsInRhcmdldEJyYW5jaCI6ImNob3JlL3Jlbm92YXRlQmFzZUJyYW5jaCJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

2 participants