-
Notifications
You must be signed in to change notification settings - Fork 306
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
TransactionCost - remove allocation #1987
Conversation
@@ -104,33 +100,35 @@ impl CostModel { | |||
); | |||
} | |||
|
|||
fn get_writable_accounts(transaction: &SanitizedTransaction) -> Vec<Pubkey> { | |||
pub fn writable_accounts_iter( |
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.
not ideal place for this function to live. Will, hopefully, put this somewhere shared after this is resolved: #1918 (comment)
While this iteration is not as fast as simply iterating over a Vec; I do not think it will be so much slower that we reduce overall performance.
cost_tracker benches:
|
@@ -426,9 +455,10 @@ mod tests { | |||
let simple_transaction = SanitizedTransaction::from_transaction_for_tests( | |||
system_transaction::transfer(mint_keypair, &keypair.pubkey(), 2, *start_hash), | |||
); | |||
let mut tx_cost = UsageCostDetails::new_with_capacity(1); | |||
tx_cost.programs_execution_cost = 5; | |||
tx_cost.writable_accounts.push(mint_keypair.pubkey()); |
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 was incorrect. Lead to test_cost_tracker_ok_add_two_same_accounts
failing when we used proper writable accounts count.
9f1fb05
to
20cda2e
Compare
20cda2e
to
7235535
Compare
cost model benches (from #2168): master:
PR:
More room for improvement here, this is slower than I'd like. But this PR is a step in the right direction. |
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.
overall the changes look great, removing the vec
from TransactionCost is a plus. Going to look more closely; after first glance, feel having to passing writable_accounts: impl Iterator<Item = &'a Pubkey>
to every cost-model functions is a bit of repetitive. Possible to to make it a member of TransactionCost
? If not, maybe cost-model functions take f(&sanitized_transaction, &tx_cost)
make more sense than f(write_lock_account_iter, &tx_cost)
. Just a quick thought tho.
Yeah I like that more than the iterator interface |
Closing this PR for now. Other work going on in area, want to avoid causing rebase issues for this relatively minor improvement. |
Problem
TransactionCost
holds an allocation to track writable accounts. This is generally not needed since we can always figure out which accounts the transaction writes since the transaction stays in scope longer thanTransactionCost
Summary of Changes
writable_accounts
fromTransactionCost
Fixes #