solana-program: only decode prior_voters if needed #34972
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
originally i wrote the
VoteState
parse to checkis_empty
and skip parsingprior_voters
if it was empty. later i got rid of this as unnecessary complexity. however it turns outprior_voters
may be fully half the CU cost of a typical vote account, 7-8k vs 15-16k totalSummary of Changes
add this logic back in for a 50% efficiency gain if
prior_voters
is empty, which is more likely than not. i wrote this to only operate with the cursor, rather than the raw input bytes, per jons suggestionalso i added bounds checking to the cursor before and after; while writing this, i discovered
Cursor
successfully returns 0 rather than erroring if it runs out of bounds. also i fixed a mistake with the tests where insufficient data was generated, making coverage of the full struct basically nil