Skip to content

Cache BLS Keys #1445

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

Closed
wants to merge 12 commits into from
Closed

Conversation

joshua-kim
Copy link
Contributor

@joshua-kim joshua-kim commented Apr 28, 2023

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

@joshua-kim joshua-kim changed the base branch from master to dev April 28, 2023 21:39
@joshua-kim joshua-kim force-pushed the get-canonical-validator-set branch from 109bec9 to 7dd0d54 Compare April 28, 2023 22:53
@joshua-kim joshua-kim force-pushed the get-canonical-validator-set branch from 7dd0d54 to 3747a44 Compare April 28, 2023 22:56
@joshua-kim joshua-kim force-pushed the get-canonical-validator-set branch from 3747a44 to 1b346c1 Compare April 29, 2023 01:55
@StephenButtolph StephenButtolph added sdk This involves SDK tooling or frameworks benchmarking labels Apr 29, 2023
PublicKey: primaryVdr.PublicKey,
Weight: vdr.Weight,
NodeID: vdr.NodeID,
PublicKey: validators.PublicKey{
Copy link
Contributor

Choose a reason for hiding this comment

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

We're probably going to want to do a followup here where we keep the serialized bytes of the keys in memory as well. Will enable us to avoid re-serializing on every call to GetValidatorSet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a followup ticket - #1508

@joshua-kim joshua-kim marked this pull request as ready for review April 30, 2023 23:57
@abi87
Copy link
Contributor

abi87 commented May 4, 2023

Some more benchmarks here #1467

@joshua-kim joshua-kim force-pushed the get-canonical-validator-set branch from 0e443a8 to 83b0a77 Compare May 5, 2023 09:30
@joshua-kim joshua-kim force-pushed the get-canonical-validator-set branch from 83b0a77 to 042792d Compare May 15, 2023 14:08
@StephenButtolph StephenButtolph added this to the v1.10.6 milestone Jul 19, 2023
@StephenButtolph StephenButtolph modified the milestones: v1.10.7, v1.10.8, v1.10.9 Aug 3, 2023
@joshua-kim joshua-kim removed the sdk This involves SDK tooling or frameworks label Aug 16, 2023
@StephenButtolph StephenButtolph modified the milestones: v1.10.9, v1.10.10 Aug 25, 2023
@StephenButtolph StephenButtolph modified the milestones: v1.10.10, v1.10.11 Sep 18, 2023
@joshua-kim joshua-kim self-assigned this Sep 19, 2023
@StephenButtolph StephenButtolph modified the milestones: v1.10.11, v1.10.12 Sep 22, 2023
@StephenButtolph StephenButtolph modified the milestones: v1.10.12, v1.10.13 Oct 5, 2023
@StephenButtolph StephenButtolph modified the milestones: v1.10.13, v1.10.14 Oct 17, 2023
@StephenButtolph StephenButtolph removed this from the v1.10.16 milestone Nov 17, 2023
Copy link

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.

@StephenButtolph
Copy link
Contributor

I made an issue to track this optimization in a broader context across the whole node: #3902

@github-project-automation github-project-automation bot moved this from Backlog 🗄️ to Done ✅ in avalanchego Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Status: In Review 👀
Development

Successfully merging this pull request may close these issues.

5 participants