avalanchego
avalanchego copied to clipboard
Cache BLS Keys
Why this should be merged
Since the P-Chain communicates with the warp
contract over GRPC, we can re-use the bytes that are coming out of grpc to pre-populate the serialized form of a bls key, avoiding re-calculating it later which turns out to be roughly half of the cpu cycles spent in GetCanonicalValidatorSet
(aside from sorting).
How this works
Pre-populates a new field that holds the cached representation of the bls key.
How this was tested
Added a benchmark test. Seeing roughly a 20% performance boost:
Before:
goos: darwin
goarch: arm64
pkg: github.com/ava-labs/avalanchego/vms/platformvm/warp
BenchmarkGetCanonicalValidatorSet
BenchmarkGetCanonicalValidatorSet/0
BenchmarkGetCanonicalValidatorSet/0-10 6599539 180.4 ns/op
BenchmarkGetCanonicalValidatorSet/1
BenchmarkGetCanonicalValidatorSet/1-10 2472804 485.5 ns/op
BenchmarkGetCanonicalValidatorSet/10
BenchmarkGetCanonicalValidatorSet/10-10 342585 3498 ns/op
BenchmarkGetCanonicalValidatorSet/100
BenchmarkGetCanonicalValidatorSet/100-10 33254 36251 ns/op
BenchmarkGetCanonicalValidatorSet/1000
BenchmarkGetCanonicalValidatorSet/1000-10 3010 388901 ns/op
BenchmarkGetCanonicalValidatorSet/10000
BenchmarkGetCanonicalValidatorSet/10000-10 260 4471217 ns/op
PASS
After:
goos: darwin
goarch: arm64
pkg: github.com/ava-labs/avalanchego/vms/platformvm/warp
BenchmarkGetCanonicalValidatorSet
BenchmarkGetCanonicalValidatorSet/0
BenchmarkGetCanonicalValidatorSet/0-10 6491647 186.2 ns/op
BenchmarkGetCanonicalValidatorSet/1
BenchmarkGetCanonicalValidatorSet/1-10 3459529 349.5 ns/op
BenchmarkGetCanonicalValidatorSet/10
BenchmarkGetCanonicalValidatorSet/10-10 557814 2129 ns/op
BenchmarkGetCanonicalValidatorSet/100
BenchmarkGetCanonicalValidatorSet/100-10 49543 24245 ns/op
BenchmarkGetCanonicalValidatorSet/1000
BenchmarkGetCanonicalValidatorSet/1000-10 4250 285461 ns/op
BenchmarkGetCanonicalValidatorSet/10000
BenchmarkGetCanonicalValidatorSet/10000-10 328 3542274 ns/op
PASS
Some more benchmarks here https://github.com/ava-labs/avalanchego/pull/1467
@joshua-kim validators have been moved to their own package. The PublicKey initialization changes cause some minor conflicts. Please solve them.
This PR has become stale because it has been open for 30 days with no activity. Adding the lifecycle/frozen
label will cause this PR to ignore lifecycle events.