-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Optimize backfill sync to efficiently use reqresp fetched block data #3669
Conversation
…p sync(block/range)
Code Climate has analyzed commit 7928f92 and detected 0 issues on this pull request. View more on Code Climate. |
Performance Report✔️ no performance regression detected Full benchmark results
|
Codecov Report
@@ Coverage Diff @@
## master #3669 +/- ##
==========================================
+ Coverage 37.13% 37.39% +0.25%
==========================================
Files 321 322 +1
Lines 8706 8796 +90
Branches 1350 1369 +19
==========================================
+ Hits 3233 3289 +56
- Misses 5330 5365 +35
+ Partials 143 142 -1 |
const block = signedBlock.message as TreeBacked<allForks.BeaconBlock>; | ||
return { | ||
key: block.slot, | ||
value: signedBlock.serialize(), |
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.
what I mean in the issue is that we return both the binary and the signed block in beaconBlocksByRange
and beaconBlocksByRoot
. So instead of returning Promise<allForks.SignedBeaconBlock[]>
in network req/resp api, return something like
type CachedBytes<T> = {bytes: Uint8Array} & T;
async beaconBlocksByRange(
peerId: PeerId,
request: phase0.BeaconBlocksByRangeRequest
): Promise<CachedBytes<allForks.SignedBeaconBlock>[]>
and consume that cached bytes
without having to call serialize()
again in BackFill sync and similar places
@dapplion do we have this type in ssz v2?
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.
yes, I was wondering about the same 🙂
This format should currently save on hashTreeRoot calcs which would amount for 9% of hashTreeRoot in verifiBlockSequence (#3657 (comment)), and may be some 2-3% on the serialize.
CachedBytes<allForks.SignedBeaconBlock> would be awesome ❤️ awaiting @dapplion 's input regarding ssz v2.
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.
Right now, ssz v2 only (optionally) caches the hashTreeRoot (of non-tree-backed values); doesn't cache the serialized bytes.
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.
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.
added caching capability as that was discussed to be out of scope for ssz v2 👍
return (typeTree.createTreeBackedFromBytes(bytes) as unknown) as T; | ||
const treeBacked = typeTree.createTreeBackedFromBytes(bytes) as unknown; | ||
if (options?.cacheBytes) { | ||
return (new Proxy({treeBacked, bytes}, cachedTreeBackedProxyHandler) as unknown) as T; |
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.
Needed another proxy as tree's proxy wasn't letting assign bytes
without going through the tree setters. May be post ssz v2 merge, it could be removed.
Closing for now since the network code has diverged. This optimization is good and should definitely be included on a future review of backfill sync |
Motivation
As @tuyennhv pointed out after doing profiler runs, backfill sync could be optimized to use treebacked data from the sync range/block by root.
This PR changes the following:
--sync.backfillBatchSize
to speciify the batch size for backfill syncDescription
Closes #3657