-
Notifications
You must be signed in to change notification settings - Fork 807
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
[Merged by Bors] - Optimize process_attestation
with active balance cache
#2560
Conversation
Testing on a Prater node with
|
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.
Great fix!
Thank you! bors r+ |
## Proposed Changes Cache the total active balance for the current epoch in the `BeaconState`. Computing this value takes around 1ms, and this was negatively impacting block processing times on Prater, particularly when reconstructing states. With a large number of attestations in each block, I saw the `process_attestations` function taking 150ms, which means that reconstructing hot states can take up to 4.65s (31 * 150ms), and reconstructing freezer states can take up to 307s (2047 * 150ms). I opted to add the cache to the beacon state rather than computing the total active balance at the start of state processing and threading it through. Although this would be simpler in a way, it would waste time, particularly during block replay, as the total active balance doesn't change for the duration of an epoch. So we save ~32ms for hot states, and up to 8.1s for freezer states (using `--slots-per-restore-point 8192`).
Pull request successfully merged into unstable. Build succeeded: |
process_attestation
with active balance cacheprocess_attestation
with active balance cache
thank you! right now https://prater.beaconcha.in is behind because this endpoint is slow (note: it works just fine on pyrmont). also some epochs will be shown with 0 eligible ether and participation-rate, we export epochs with 0 values on timeout right now. will fix these epochs after deployed fix. |
Proposed Changes
Cache the total active balance for the current epoch in the
BeaconState
. Computing this value takes around 1ms, and this was negatively impacting block processing times on Prater, particularly when reconstructing states.With a large number of attestations in each block, I saw the
process_attestations
function taking 150ms, which means that reconstructing hot states can take up to 4.65s (31 * 150ms), and reconstructing freezer states can take up to 307s (2047 * 150ms).I opted to add the cache to the beacon state rather than computing the total active balance at the start of state processing and threading it through. Although this would be simpler in a way, it would waste time, particularly during block replay, as the total active balance doesn't change for the duration of an epoch. So we save ~32ms for hot states, and up to 8.1s for freezer states (using
--slots-per-restore-point 8192
).