Avoid alloc due to vector pushes (#6632)
This commit is contained in:
parent
83d5115a02
commit
5264fded00
|
@ -116,8 +116,8 @@ impl Accounts {
|
||||||
|
|
||||||
// There is no way to predict what program will execute without an error
|
// There is no way to predict what program will execute without an error
|
||||||
// If a fee can pay for execution then the program will be scheduled
|
// If a fee can pay for execution then the program will be scheduled
|
||||||
let mut accounts: TransactionAccounts = vec![];
|
let mut accounts: TransactionAccounts = Vec::with_capacity(message.account_keys.len());
|
||||||
let mut rents: TransactionRents = vec![];
|
let mut rents: TransactionRents = Vec::with_capacity(message.account_keys.len());
|
||||||
for key in message
|
for key in message
|
||||||
.account_keys
|
.account_keys
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -633,7 +633,7 @@ impl Accounts {
|
||||||
res: &'a [Result<()>],
|
res: &'a [Result<()>],
|
||||||
loaded: &'a mut [Result<TransactionLoadResult>],
|
loaded: &'a mut [Result<TransactionLoadResult>],
|
||||||
) -> Vec<(&'a Pubkey, &'a Account)> {
|
) -> Vec<(&'a Pubkey, &'a Account)> {
|
||||||
let mut accounts = Vec::new();
|
let mut accounts = Vec::with_capacity(loaded.len());
|
||||||
for (i, (raccs, tx)) in loaded
|
for (i, (raccs, tx)) in loaded
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.zip(OrderedIterator::new(txs, txs_iteration_order))
|
.zip(OrderedIterator::new(txs, txs_iteration_order))
|
||||||
|
|
|
@ -811,7 +811,7 @@ impl AccountsDB {
|
||||||
(meta, *account)
|
(meta, *account)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let mut infos: Vec<AccountInfo> = vec![];
|
let mut infos: Vec<AccountInfo> = Vec::with_capacity(with_meta.len());
|
||||||
while infos.len() < with_meta.len() {
|
while infos.len() < with_meta.len() {
|
||||||
let storage = self.find_storage_candidate(slot_id);
|
let storage = self.find_storage_candidate(slot_id);
|
||||||
let rvs = storage
|
let rvs = storage
|
||||||
|
@ -882,15 +882,19 @@ impl AccountsDB {
|
||||||
accounts: &[(&Pubkey, &Account)],
|
accounts: &[(&Pubkey, &Account)],
|
||||||
) -> (Vec<(Slot, AccountInfo)>, u64) {
|
) -> (Vec<(Slot, AccountInfo)>, u64) {
|
||||||
let mut reclaims: Vec<(Slot, AccountInfo)> = Vec::with_capacity(infos.len() * 2);
|
let mut reclaims: Vec<(Slot, AccountInfo)> = Vec::with_capacity(infos.len() * 2);
|
||||||
let mut inserts = vec![];
|
|
||||||
let index = self.accounts_index.read().unwrap();
|
let index = self.accounts_index.read().unwrap();
|
||||||
let mut update_index_work = Measure::start("update_index_work");
|
let mut update_index_work = Measure::start("update_index_work");
|
||||||
for (info, pubkey_account) in infos.into_iter().zip(accounts.iter()) {
|
let inserts: Vec<_> = infos
|
||||||
|
.into_iter()
|
||||||
|
.zip(accounts.iter())
|
||||||
|
.filter_map(|(info, pubkey_account)| {
|
||||||
let pubkey = pubkey_account.0;
|
let pubkey = pubkey_account.0;
|
||||||
if let Some(info) = index.update(slot_id, pubkey, info, &mut reclaims) {
|
index
|
||||||
inserts.push((pubkey, info));
|
.update(slot_id, pubkey, info, &mut reclaims)
|
||||||
}
|
.map(|info| (pubkey, info))
|
||||||
}
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
let last_root = index.last_root;
|
let last_root = index.last_root;
|
||||||
drop(index);
|
drop(index);
|
||||||
if !inserts.is_empty() {
|
if !inserts.is_empty() {
|
||||||
|
@ -955,10 +959,11 @@ impl AccountsDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_accounts(&self, slot_id: Slot, accounts: &[(&Pubkey, &Account)]) -> Vec<Hash> {
|
fn hash_accounts(&self, slot_id: Slot, accounts: &[(&Pubkey, &Account)]) -> Vec<Hash> {
|
||||||
let mut hashes = vec![];
|
|
||||||
let mut hash_state = BankHash::default();
|
let mut hash_state = BankHash::default();
|
||||||
let mut had_account = false;
|
let mut had_account = false;
|
||||||
for (pubkey, account) in accounts {
|
let hashes: Vec<_> = accounts
|
||||||
|
.iter()
|
||||||
|
.map(|(pubkey, account)| {
|
||||||
if !sysvar::check_id(&account.owner) {
|
if !sysvar::check_id(&account.owner) {
|
||||||
let hash = BankHash::from_hash(&account.hash);
|
let hash = BankHash::from_hash(&account.hash);
|
||||||
let new_hash = Self::hash_account(slot_id, account, pubkey);
|
let new_hash = Self::hash_account(slot_id, account, pubkey);
|
||||||
|
@ -974,11 +979,12 @@ impl AccountsDB {
|
||||||
hash_state.xor(hash);
|
hash_state.xor(hash);
|
||||||
}
|
}
|
||||||
hash_state.xor(new_bank_hash);
|
hash_state.xor(new_bank_hash);
|
||||||
hashes.push(new_hash);
|
new_hash
|
||||||
} else {
|
} else {
|
||||||
hashes.push(Hash::default());
|
Hash::default()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
if had_account {
|
if had_account {
|
||||||
self.xor_in_hash_state(slot_id, hash_state);
|
self.xor_in_hash_state(slot_id, hash_state);
|
||||||
|
|
|
@ -292,7 +292,7 @@ impl AppendVec {
|
||||||
hashes: &[Hash],
|
hashes: &[Hash],
|
||||||
) -> Vec<usize> {
|
) -> Vec<usize> {
|
||||||
let mut offset = self.append_offset.lock().unwrap();
|
let mut offset = self.append_offset.lock().unwrap();
|
||||||
let mut rv = vec![];
|
let mut rv = Vec::with_capacity(accounts.len());
|
||||||
for ((stored_meta, account), hash) in accounts.iter().zip(hashes) {
|
for ((stored_meta, account), hash) in accounts.iter().zip(hashes) {
|
||||||
let meta_ptr = stored_meta as *const StoredMeta;
|
let meta_ptr = stored_meta as *const StoredMeta;
|
||||||
let account_meta = AccountMeta {
|
let account_meta = AccountMeta {
|
||||||
|
|
Loading…
Reference in New Issue