Optimize update_index to avoid vec copies#7624
Conversation
There was a problem hiding this comment.
Pull Request Overview
Refactors the handle_reclaims function to improve performance by avoiding unnecessary vector copying operations and simplifying conditional logic around empty reclaims.
- Simplified the
handle_reclaimsfunction signature by removing theOptionwrapper - Added early returns for empty reclaims to avoid unnecessary processing
- Updated return type from flattened
SlotListtoVec<SlotList>to preserve chunking structure
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7624 +/- ##
========================================
Coverage 82.9% 82.9%
========================================
Files 823 823
Lines 360972 360978 +6
========================================
+ Hits 299404 299512 +108
+ Misses 61568 61466 -102 🚀 New features to boost your workflow:
|
015f484 to
19af0e4
Compare
5f90d89 to
496999e
Compare
496999e to
5b3ac14
Compare
brooksprumo
left a comment
There was a problem hiding this comment.
I like removing the option wrappers on the reclaims iterators!
|
Also, can the PR be split? Seems like one can be removing the Option wrapper on the iter, and the other can be about how we return results from |
yeah. #8113 is the the split pr for removing option wrapper on iter. Once #8113 is merged. I will rebase this one for just the update_index() change. In the meantime, I will mark this one as draft. |
5b3ac14 to
12185f4
Compare
12185f4 to
2221fed
Compare
|
Now this PR is ready to review again. Thanks! |
|
How was this determined to be an actual problem? Is there a perf profile or metric? Do we end up with a lot of reclaims usually? I'm wondering if we actually end up needing to grow the vec and reallocate often. |
|
Before we have obsolete accounts, there are no reclaims as the code snippet shows - "IgnoreReclaims" is passed to update_index. |
|
The above chat shows the stats for `accounts_db-flush_accounts_cache.handle_reclaims_elapsed_us'. |
Not a problem now. But will be a problem when we enable mark_obsolete_account. I notice this when I review one of the mark_obsolete_accounts PR.
Yes, when we enable mark_obsolete_accounts. And we will spend allocations to collect those reclaims in the original code path before this PR. |
|
^To make the measurement of reclaims more intuitive, this above follow-up PR added a stat to track the number of reclaims. |
|
^ Above is the update_index_us after this PR. |
yup! |





Problem
This PR optimizes update_index function to avoid vector copies.
Measurement on mainnet shows more than 50% cut of update_index_time when mark obsolete account is enabled.
#7624 (comment)
Summary of Changes
Fixes #