One less alloc per transaction (#9705)

* One less alloc per transaction

* Fix benches

* Fix compiler warnings in bench build

* Fix move build

* Fix bench
This commit is contained in:
Greg Fitzgerald
2020-04-24 13:03:46 -06:00
committed by GitHub
parent 767a0f9384
commit 76b1c2baf0
24 changed files with 95 additions and 106 deletions

View File

@ -29,7 +29,7 @@ use solana_sdk::timing::{duration_as_us, timestamp};
use solana_sdk::transaction::Transaction;
use std::sync::atomic::Ordering;
use std::sync::mpsc::Receiver;
use std::sync::{Arc, RwLock};
use std::sync::Arc;
use std::time::{Duration, Instant};
use test::Bencher;
@ -117,7 +117,7 @@ fn make_programs_txs(txes: usize, hash: Hash) -> Vec<Transaction> {
let to_key = Pubkey::new_rand();
instructions.push(system_instruction::transfer(&from_key.pubkey(), &to_key, 1));
}
let mut new = Transaction::new_unsigned_instructions(instructions);
let mut new = Transaction::new_unsigned_instructions(&instructions);
new.sign(&[&from_key], hash);
new
})

View File

@ -9,7 +9,6 @@ use solana_core::contact_info::ContactInfo;
use solana_ledger::shred::Shred;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::timing::timestamp;
use std::sync::RwLock;
use std::{
collections::HashMap,
net::UdpSocket,
@ -22,7 +21,7 @@ fn broadcast_shreds_bench(bencher: &mut Bencher) {
solana_logger::setup();
let leader_pubkey = Pubkey::new_rand();
let leader_info = Node::new_localhost_with_pubkey(&leader_pubkey);
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.info.clone());
let cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.info.clone());
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
const NUM_SHREDS: usize = 32;

View File

@ -29,7 +29,7 @@ use test::Bencher;
#[bench]
fn bench_retransmitter(bencher: &mut Bencher) {
solana_logger::setup();
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
let cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
const NUM_PEERS: usize = 4;
let mut peer_sockets = Vec::new();
for _ in 0..NUM_PEERS {

View File

@ -823,7 +823,7 @@ impl ReplayStage {
vote,
);
let mut vote_tx = Transaction::new_with_payer(vec![vote_ix], Some(&node_keypair.pubkey()));
let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey()));
let blockhash = bank.last_blockhash();
vote_tx.partial_sign(&[node_keypair.as_ref()], blockhash);

View File

@ -1506,7 +1506,7 @@ pub mod tests {
);
let vote_tx = Transaction::new_signed_instructions(
&[&leader_vote_keypair],
vec![vote_ix],
&[vote_ix],
Hash::default(),
);
let shreds = entries_to_test_shreds(
@ -2777,7 +2777,7 @@ pub mod tests {
let transaction = Transaction::new_signed_instructions(
&[&alice, &alice_vote_keypair],
instructions,
&instructions,
bank.last_blockhash(),
);
bank.process_transaction(&transaction)
@ -2807,7 +2807,7 @@ pub mod tests {
bank.freeze();
// Votes
let instructions = vec![
let instructions = [
vote_instruction::vote(
&leader_vote_keypair.pubkey(),
&leader_vote_keypair.pubkey(),
@ -2835,7 +2835,7 @@ pub mod tests {
));
let transaction = Transaction::new_signed_with_payer(
instructions,
&instructions,
Some(&alice.pubkey()),
&[&alice, &leader_vote_keypair, &alice_vote_keypair],
bank.last_blockhash(),

View File

@ -527,7 +527,7 @@ mod tests {
);
let tx = Transaction::new_signed_instructions(
&[&contract_funds, &contract_state],
ixs,
&ixs,
blockhash,
);
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions).unwrap();
@ -571,7 +571,7 @@ mod tests {
&contract_state.pubkey(),
&bob_pubkey,
);
let tx = Transaction::new_signed_instructions(&[&witness], vec![ix], blockhash);
let tx = Transaction::new_signed_instructions(&[&witness], &[ix], blockhash);
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions).unwrap();
sleep(Duration::from_millis(200));

View File

@ -86,7 +86,7 @@ mod tests {
// create accounts
let bank = Arc::new(Bank::new_from_parent(&bank, &keypair.pubkey(), 1));
let account_ix = storage_instruction::create_storage_account(
let account_ixs = storage_instruction::create_storage_account(
&mint_keypair.pubkey(),
&Pubkey::new_rand(),
&archiver_keypair.pubkey(),
@ -95,7 +95,7 @@ mod tests {
);
let account_tx = Transaction::new_signed_instructions(
&[&mint_keypair, &archiver_keypair],
account_ix,
&account_ixs,
bank.last_blockhash(),
);
bank.process_transaction(&account_tx).expect("create");