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: faster hash marshaling methods #183

Merged
merged 3 commits into from
Jun 20, 2024
Merged

Conversation

cristaloleg
Copy link
Contributor

Overview

Reduce a bit of allocations and cpu time in Hash arshaling methods. Same behaviour as before but slightly in another way: instead of operations on string we can do this on []byte. As a result we now have tests for that.

go-header % go-perftuner bstat a.txt b.txt
args: [a.txt b.txt]name                         old time/op    new time/op    delta
HashMarshaling/String-10        798ns ± 0%     613ns ± 0%  -23.08%  (p=0.002 n=6+6)
HashMarshaling/Marshal-10      1.11µs ± 0%    0.84µs ± 0%  -24.55%  (p=0.004 n=5+6)
HashMarshaling/Unmarshal-10     333ns ±11%     277ns ± 1%  -16.92%  (p=0.004 n=5+6)

name                         old alloc/op   new alloc/op   delta
HashMarshaling/String-10         192B ± 0%      128B ± 0%  -33.33%  (p=0.002 n=6+6)
HashMarshaling/Marshal-10        296B ± 0%      104B ± 0%  -64.86%  (p=0.002 n=6+6)
HashMarshaling/Unmarshal-10      128B ± 0%       32B ± 0%  -75.00%  (p=0.002 n=6+6)

name                         old allocs/op  new allocs/op  delta
HashMarshaling/String-10         3.00 ± 0%      2.00 ± 0%        ~  (p=0.002 n=6+6)
HashMarshaling/Marshal-10        5.00 ± 0%      2.00 ± 0%  -60.00%  (p=0.002 n=6+6)
HashMarshaling/Unmarshal-10      2.00 ± 0%      1.00 ± 0%        ~  (p=0.002 n=6+6)

@cristaloleg cristaloleg changed the title Faster hash arshaling methods perf: faster hash arshaling methods May 27, 2024
Wondertan
Wondertan previously approved these changes May 27, 2024
Copy link
Member

@Wondertan Wondertan left a comment

Choose a reason for hiding this comment

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

Cute!

hash.go Outdated Show resolved Hide resolved
@renaynay renaynay changed the title perf: faster hash arshaling methods perf: faster hash marshaling methods May 27, 2024
Wondertan
Wondertan previously approved these changes May 27, 2024
@cristaloleg
Copy link
Contributor Author

@renaynay added a fuzzing test for hexToUpper (to run: go test -v -run=^$ -fuzz=Fuzz_hexToUpper .)

@cristaloleg cristaloleg enabled auto-merge (squash) May 30, 2024 16:45
@cristaloleg cristaloleg merged commit 41d0d7c into main Jun 20, 2024
4 checks passed
@cristaloleg cristaloleg deleted the faster-hash-arshaling branch June 20, 2024 11:12
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