refactor: Optimize instruction_accounts
creation in invoke_context
#2475
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
PS: I am a fairly new contributor, and a student of the code base, so these changes may be reviewed with a grain of salt.
The current implementation, while functional, has room for improvement in terms of performance and readability. These changes aim to make the code more idiomatic and potentially more efficient, especially when dealing with large datasets or frequent calls.
Summary of Changes
This PR introduces a tiny optimization for the creation of
instruction_accounts
in theinvoke_context
file of the Anza client implementation for Solana. It also hopes to improve code readability, and adherence to general Rust idioms.Changes
clone()
withcloned()
methodmap()
Benefits
cloned()
instead of explicitclone()
is more idiomatic and potentially more efficient.Future Optimizations
While not included in this PR, here are some ideas for future optimizations:
duplicate_indicies
is known in advance, pre-allocating theVec
could provide a small performance boost.Vec
, if possible.Performance Impact
While the performance difference is likely minimal for small datasets or infrequent calls, it could be noticeable for large-scale operations. Benchmarking is recommended to quantify the improvement.
Please review and let me know if you have any questions or suggestions for further improvements!