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

Improved performance of the version.GetHumanVersion function by 50% on memory allocation. #11507

Merged
merged 3 commits into from
Dec 9, 2021

Conversation

haxandmat
Copy link
Contributor

Improved performance and added benchmark for func version.GetHumanVersion.

Instructions:

$ go install golang.org/x/perf/cmd/benchstat@latest

$ go test -bench=GetHumanVersion -count 5 -benchmem ./version > old.txt
$ go test -bench=GetHumanVersion -count 5 -benchmem ./version > new.txt

$ benchstat old.txt new.txt

Results

name               old time/op    new time/op    delta
GetHumanVersion-8     177ns ± 2%      80ns ± 3%  -54.53%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
GetHumanVersion-8     32.0B ± 0%     16.0B ± 0%  -50.00%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
GetHumanVersion-8      3.00 ± 0%      2.00 ± 0%  -33.33%  (p=0.008 n=5+5)

@vercel vercel bot temporarily deployed to Preview – consul November 5, 2021 15:32 Inactive
@vercel vercel bot temporarily deployed to Preview – consul November 5, 2021 16:11 Inactive
@haxandmat haxandmat changed the title Improve performance func version.GetHumanVersion Improved performance of the version.GetHumanVersion function by 50% on memory allocation. Nov 5, 2021
@markan markan self-assigned this Nov 10, 2021
@Amier3 Amier3 requested a review from markan November 10, 2021 18:28
Copy link
Contributor

@eculver eculver left a comment

Choose a reason for hiding this comment

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

LGTM!

@eculver eculver self-assigned this Nov 16, 2021

func BenchmarkGetHumanVersion(b *testing.B) {
for i := 0; i < b.N; i++ {
GetHumanVersion()
Copy link
Contributor

@eculver eculver Nov 16, 2021

Choose a reason for hiding this comment

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

We're a little surprised that, because there's no assignment here, the compiler doesn't do some optimizations but looks good.

@eculver
Copy link
Contributor

eculver commented Dec 9, 2021

I'm not sure why this is still stuck but without the report back from CircleCI and without a new commit, it's just going to stay stuck. I tested this locally so I don't see any harm in just merging it so that's what I'll do :)

@eculver eculver merged commit d013ded into hashicorp:main Dec 9, 2021
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/522907.

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.

4 participants