-
Notifications
You must be signed in to change notification settings - Fork 844
perf: Optimize BLS key usage #4784
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
base: master
Are you sure you want to change the base?
perf: Optimize BLS key usage #4784
Conversation
|
@yacovm the eager initialization did indeed tank the performance: BenchmarkFlattenValidatorSet (Validator Set Creation)
BenchmarkGetCanonicalValidatorSet (Full Validator Set Retrieval)
However maybe we are okay with these tradeoffs, as we do
|
|
I can also revert to 4f55cf3 for the original performance gains. I guess the larger question is does IRL usage mimic the benchmark or nah. |
|
I added a new benchmark
|
|
Performance Results (ns/op)
|
|
My vote: revert all changes to 4f55cf3, but keep the new benchmark. |
|
We should optimize the transaction validation path, so let's revert my idea 👍 |
Reverted! |
| require.Equal(test.want.TotalWeight, got.TotalWeight) | ||
| require.Len(got.Validators, len(test.want.Validators)) | ||
| for i, wantVdr := range test.want.Validators { | ||
| gotVdr := got.Validators[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this too:
gotVdr.PublicKey = nil
wantVdr.PublicKey = nil
require.Equal(wantVdr, gotVdr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| func (v L1Validator) effectivePublicKey() *bls.PublicKey { | ||
| if v.IsActive() { | ||
| return bls.PublicKeyFromValidUncompressedBytes(v.PublicKey) | ||
| if !v.IsActive() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that it's important but why the order change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just matches the early return pattern others have stressed.
|
Which conventional commits spec are we using? Under some this isn't a |
you're right - it should be perf. I just started doing it a couple months ago, and have been using these:
|
alarso16
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EVM code looks fine, but I would check for more mistakes like the one I noticed
alarso16
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been corrected, seems fine

Why this should be merged
This PR eliminates redundant BLS public key conversions throughout the validator codebase, which is a somewhat significant performance increase.
This is measured in the following benchmark:
go test -bench=. -benchmem ./vms/platformvm/warp | grep "BenchmarkGetCanonicalValidatorSet"A summary of results:
How this works
For prior context see
Closes #3902
Warp struct
PublicKeyfield from Warp struct, keeping onlyPublicKeyBytesFlattenValidatorSetto usePublicKeyBytesdirectlyGetValidatorOutputPublicKeyBytesfield to store uncompressed bytes (96 bytes)ApplyValidatorPublicKeyDiffs,gRPCclient, validator setMap()functionThere's no breaking changes in this PR, as the cache fields aren't serialized, so no concerns there either.
How this was tested
CI, the
BenchmarkGetCanonicalValidatorSetNeed to be documented in RELEASES.md?
No