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 strings builder for attester lock key #8349

Merged
merged 2 commits into from Jan 27, 2021
Merged

Conversation

terencechain
Copy link
Member

What type of PR is this?

Minor improvement

What does this PR do? Why is it needed?

Use strings builder to construct lock key for attesting. It is more performant than casting. It's about 70% faster and 10% less bytes per allocation.

BenchmarkTwoInputs-12    	 2901903	       397 ns/op	     432 B/op	       7 allocs/op
BenchmarkOneInputWithConcat-12    	 3710899	       316 ns/op	     448 B/op	       7 allocs/op
BenchmarkOneInputWithStringBuilder-12    	 4719397	       245 ns/op	     408 B/op	       7 allocs/op


func BenchmarkTwoInputs(b *testing.B) {
	pubKey := [48]byte{'a'}
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		mputil.NewMultilock(fmt.Sprint(roleAttester), string(pubKey[:]))
	}
}

func BenchmarkOneInputWithConcat(b *testing.B) {
	pubKey := [48]byte{'a'}
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		mputil.NewMultilock(fmt.Sprint(roleAttester) + string(pubKey[:]))
	}
}

func BenchmarkOneInputWithStringBuilder(b *testing.B) {
	pubKey := [48]byte{'a'}
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		var b strings.Builder
		b.WriteByte(byte(roleAttester))
		b.Write(pubKey[:])
		mputil.NewMultilock(b.String())
	}
}

Which issues(s) does this PR fix?

N/A

Other notes for review
Leaving proposing side untouched because it's less relevant

@terencechain terencechain added the Ready For Review A pull request ready for code review label Jan 27, 2021
@terencechain terencechain self-assigned this Jan 27, 2021
@terencechain terencechain requested a review from a team as a code owner January 27, 2021 21:19
@prylabs-bulldozer prylabs-bulldozer bot merged commit 2bf03d5 into develop Jan 27, 2021
@delete-merged-branch delete-merged-branch bot deleted the better-lock-str branch January 27, 2021 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants