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

Use HMAC one-shot methods instead of instances #330

Merged

Conversation

jevgenigeurtsen
Copy link
Contributor

@jevgenigeurtsen jevgenigeurtsen commented Jun 23, 2023

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

As recommended by Microsoft (ref: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1850
and dotnet/runtime#40579) we should favor the one-shot HashData over the ComputeHash methods whilst hashing HMAC hashes.

I've modified the source code and ran some benchmarks, the performance gain is minimal, but its still there:

|   Method |      Job |  Runtime | sizeKey | sizeInput |     Mean |    Error |   StdDev |   Gen0 | Allocated |
|--------- |--------- |--------- |-------- |---------- |---------:|---------:|---------:|-------:|----------:|
| Instance | .NET 6.0 | .NET 6.0 |      64 |        96 | 581.8 ns | 11.36 ns | 16.29 ns | 0.0420 |     536 B |
|  OneShot | .NET 6.0 | .NET 6.0 |      64 |        96 | 356.7 ns |  7.15 ns |  7.65 ns | 0.0119 |     152 B |
| Instance | .NET 7.0 | .NET 7.0 |      64 |        96 | 604.6 ns | 10.31 ns |  9.64 ns | 0.0420 |     528 B |
|  OneShot | .NET 7.0 | .NET 7.0 |      64 |        96 | 361.9 ns |  6.17 ns |  5.47 ns | 0.0119 |     152 B |

Cheers!

@CLAassistant
Copy link

CLAassistant commented Jun 23, 2023

CLA assistant check
All committers have signed the CLA.

@JimBobSquarePants JimBobSquarePants added this to the v3.1.0 milestone Jun 25, 2023
@codecov
Copy link

codecov bot commented Jun 25, 2023

Codecov Report

Merging #330 (a32e159) into main (93d73f0) will increase coverage by 0%.
The diff coverage is 100%.

@@         Coverage Diff         @@
##           main   #330   +/-   ##
===================================
  Coverage    85%    85%           
===================================
  Files        82     82           
  Lines      2336   2334    -2     
  Branches    347    348    +1     
===================================
  Hits       1998   1998           
+ Misses      235    233    -2     
  Partials    103    103           
Flag Coverage Δ
unittests 85% <100%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/ImageSharp.Web/HMACUtilities.cs 85% <100%> (-2%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

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

Ah this is great! The difference here will absolutely add up. Thanks!

@JimBobSquarePants JimBobSquarePants merged commit 74424f7 into SixLabors:main Jun 25, 2023
renovate bot referenced this pull request in orso-co/Orso.Arpa.Api Dec 8, 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 |
|---|---|---|---|---|---|
|
[SixLabors.ImageSharp.Web](https://togithub.com/SixLabors/ImageSharp.Web)
| `3.0.1` -> `3.1.0` |
[![age](https://developer.mend.io/api/mc/badges/age/nuget/SixLabors.ImageSharp.Web/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/nuget/SixLabors.ImageSharp.Web/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/nuget/SixLabors.ImageSharp.Web/3.0.1/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/nuget/SixLabors.ImageSharp.Web/3.0.1/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>SixLabors/ImageSharp.Web (SixLabors.ImageSharp.Web)</summary>

###
[`v3.1.0`](https://togithub.com/SixLabors/ImageSharp.Web/releases/tag/v3.1.0)

#### What's Changed

- Remove async HMAC operations. by
[@&#8203;JimBobSquarePants](https://togithub.com/JimBobSquarePants) in
[https://github.com/SixLabors/ImageSharp.Web/pull/327](https://togithub.com/SixLabors/ImageSharp.Web/pull/327)
- Use HMAC one-shot methods instead of instances by
[@&#8203;jevgenigeurtsen](https://togithub.com/jevgenigeurtsen) in
[https://github.com/SixLabors/ImageSharp.Web/pull/330](https://togithub.com/SixLabors/ImageSharp.Web/pull/330)
- Bump actions/checkout from 3 to 4 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/SixLabors/ImageSharp.Web/pull/336](https://togithub.com/SixLabors/ImageSharp.Web/pull/336)
- 3.1 release compatibility by
[@&#8203;mdupras](https://togithub.com/mdupras) in
[https://github.com/SixLabors/ImageSharp.Web/pull/341](https://togithub.com/SixLabors/ImageSharp.Web/pull/341)
- Update Imagesharp by
[@&#8203;JimBobSquarePants](https://togithub.com/JimBobSquarePants) in
[https://github.com/SixLabors/ImageSharp.Web/pull/345](https://togithub.com/SixLabors/ImageSharp.Web/pull/345)

#### New Contributors

- [@&#8203;jevgenigeurtsen](https://togithub.com/jevgenigeurtsen) made
their first contribution in
[https://github.com/SixLabors/ImageSharp.Web/pull/330](https://togithub.com/SixLabors/ImageSharp.Web/pull/330)

**Full Changelog**:
SixLabors/ImageSharp.Web@v3.0.1...v3.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,every
weekend,before 5am every weekday" in timezone Europe/Berlin, Automerge -
At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **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/orso-co/Orso.Arpa.Api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44Ny4yIiwidXBkYXRlZEluVmVyIjoiMzcuODcuMiIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot referenced this pull request in orso-co/Orso.Arpa.Api Dec 9, 2023
…845)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[SixLabors.ImageSharp.Web.Providers.Azure](https://togithub.com/SixLabors/ImageSharp.Web)
| `3.0.1` -> `3.1.0` |
[![age](https://developer.mend.io/api/mc/badges/age/nuget/SixLabors.ImageSharp.Web.Providers.Azure/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/nuget/SixLabors.ImageSharp.Web.Providers.Azure/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/nuget/SixLabors.ImageSharp.Web.Providers.Azure/3.0.1/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/nuget/SixLabors.ImageSharp.Web.Providers.Azure/3.0.1/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>SixLabors/ImageSharp.Web
(SixLabors.ImageSharp.Web.Providers.Azure)</summary>

###
[`v3.1.0`](https://togithub.com/SixLabors/ImageSharp.Web/releases/tag/v3.1.0)

#### What's Changed

- Remove async HMAC operations. by
[@&#8203;JimBobSquarePants](https://togithub.com/JimBobSquarePants) in
[https://github.com/SixLabors/ImageSharp.Web/pull/327](https://togithub.com/SixLabors/ImageSharp.Web/pull/327)
- Use HMAC one-shot methods instead of instances by
[@&#8203;jevgenigeurtsen](https://togithub.com/jevgenigeurtsen) in
[https://github.com/SixLabors/ImageSharp.Web/pull/330](https://togithub.com/SixLabors/ImageSharp.Web/pull/330)
- Bump actions/checkout from 3 to 4 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/SixLabors/ImageSharp.Web/pull/336](https://togithub.com/SixLabors/ImageSharp.Web/pull/336)
- 3.1 release compatibility by
[@&#8203;mdupras](https://togithub.com/mdupras) in
[https://github.com/SixLabors/ImageSharp.Web/pull/341](https://togithub.com/SixLabors/ImageSharp.Web/pull/341)
- Update Imagesharp by
[@&#8203;JimBobSquarePants](https://togithub.com/JimBobSquarePants) in
[https://github.com/SixLabors/ImageSharp.Web/pull/345](https://togithub.com/SixLabors/ImageSharp.Web/pull/345)

#### New Contributors

- [@&#8203;jevgenigeurtsen](https://togithub.com/jevgenigeurtsen) made
their first contribution in
[https://github.com/SixLabors/ImageSharp.Web/pull/330](https://togithub.com/SixLabors/ImageSharp.Web/pull/330)

**Full Changelog**:
SixLabors/ImageSharp.Web@v3.0.1...v3.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,every
weekend,before 5am every weekday" in timezone Europe/Berlin, Automerge -
At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **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/orso-co/Orso.Arpa.Api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44Ny4yIiwidXBkYXRlZEluVmVyIjoiMzcuODcuMiIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AifQ==-->

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.

3 participants