-
Notifications
You must be signed in to change notification settings - Fork 5.5k
rework hash calculation to not keep slot and write version #17685
rework hash calculation to not keep slot and write version #17685
Conversation
|
total went from 6.0s (master) to 6.7s (this pr). |
956bb42 to
c3e3743
Compare
Codecov Report
@@ Coverage Diff @@
## master #17685 +/- ##
========================================
Coverage 82.7% 82.8%
========================================
Files 431 433 +2
Lines 120590 120773 +183
========================================
+ Hits 99839 100031 +192
+ Misses 20751 20742 -9 |
| // first entry for this key that starts in our slice | ||
| result.push(now.hash); | ||
| sum += now.lamports as u128; | ||
| let mut now = &slice[i]; |
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.
The main change here is that we need to find the last entry for each pubkey. The previous code wanted the first item. Since we read directly from appendvecs and write_versions increase as we read, this is the natural sort order.
runtime/src/accounts_db.rs
Outdated
| }); | ||
| } | ||
| } else { | ||
| // we have to call the scan_func in order of write_version within a slot if there are multiple storages per slot |
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.
this messy code is required if we have > 1 append vec per slot. We need to write_version to be in increasing order in the final accumulated results.
|
Building off this pr, the next step gets us from 6s (master) to 3.6s by reworking flatten and sort. |
sakridge
left a comment
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.
looks good
c3e3743 to
08c40ab
Compare
|
it turns out there is no discernible penalty for using the multiple storages/slot code path all the time, so that makes things simpler. |
08c40ab to
c0da989
Compare
* rework hash calculation to not keep slot and write version * refactor functions and add tests * always use multiple slot code path (cherry picked from commit b5bb91b)
…17794) * rework hash calculation to not keep slot and write version * refactor functions and add tests * always use multiple slot code path (cherry picked from commit b5bb91b) Co-authored-by: Jeff Washington (jwash) <[email protected]>
Problem
It is constant time work to sort 400k storages by slot as opposed to n*lg(n)? [n=# accounts] work to sort account data by slot later.
Also, dragging around Slot and write_version per account can get expensive.
Summary of Changes
Take advantage of the fact that storages are sorted by slot to reduce the data we keep and eventually speed up hash and lamport calculation overall. Note that this isn't faster overall yet. So, this pr likely won't be actually submitted until the next phases and supporting pieces are ready. But, this is a logical unit of work. And, it isn't a serious regression and uses less memory, so there are some tradeoffs. With different bin tuning, this algorithm can be as fast or faster as-is.
We eliminate a write version and a slot for each account entry we find (keep in mind there are duplicates).
Fixes #