-
Notifications
You must be signed in to change notification settings - Fork 1k
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 New Cache Key For Unaggregated Attestations #14590
base: develop
Are you sure you want to change the base?
Conversation
@@ -328,3 +326,15 @@ func (s *Service) hasBlockAndState(ctx context.Context, blockRoot [32]byte) bool | |||
hasState := hasStateSummary || s.cfg.beaconDB.HasState(ctx, blockRoot) | |||
return hasState && s.cfg.chain.HasBlock(ctx, blockRoot) | |||
} | |||
|
|||
func seenAttCacheKey(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregationBits []byte) string { | |||
totalLen := 8 + 8 + len(aggregationBits) |
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 might be helpful to add an explanation of what these numbers represent for anyone unfamiliar with the code. Otherwise they just seem like magic numbers
@@ -328,3 +326,15 @@ func (s *Service) hasBlockAndState(ctx context.Context, blockRoot [32]byte) bool | |||
hasState := hasStateSummary || s.cfg.beaconDB.HasState(ctx, blockRoot) | |||
return hasState && s.cfg.chain.HasBlock(ctx, blockRoot) | |||
} | |||
|
|||
func seenAttCacheKey(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregationBits []byte) string { |
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.
A benchmark test would be nice so that we can see the before/after improvements.
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.
Benchmark between old and new implementations:
goos: linux
goarch: amd64
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkCacheKeyImplementations
BenchmarkCacheKeyImplementations/Old_Cache_Key_Implementation
BenchmarkCacheKeyImplementations/Old_Cache_Key_Implementation-8 7620234 169.0 ns/op 280 B/op 4 allocs/op
BenchmarkCacheKeyImplementations/New_Cache_Key_Implementation
BenchmarkCacheKeyImplementations/New_Cache_Key_Implementation-8 35468606 31.01 ns/op 24 B/op 1 allocs/op
|
||
// Avoid copying to reduce allocation when casting. It is guaranteed to be immutable as the | ||
// slice is only created in this method and isn't accessed/returned anywhere else. | ||
return unsafe.String(&key[0], len(key)) // #nosec G103 |
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.
Can you use the same bytesutil.UnsafeCastToString from #14591 ?
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.
Will do after that PR is merged in and remove this
What type of PR is this?
Optimization
What does this PR do? Why is it needed?
This optimizes the cache key computation for specific attestation and reduces the amount of memory allocated. In certain networks, this is a high traffic path which leads to unnecessary allocation of memory.
Benchmarks of New Implementation:
Which issues(s) does this PR fix?
N.A
Other notes for review
Acknowledgements