Use cache for dll symbols (#3950)

Speeds up loaded programs.
This commit is contained in:
sakridge
2019-04-23 17:25:03 -07:00
committed by GitHub
parent f2e2106f62
commit 23c01473a0
2 changed files with 28 additions and 3 deletions

View File

@ -2,10 +2,18 @@ use crate::native_loader;
use crate::system_instruction_processor;
use solana_sdk::account::{create_keyed_accounts, Account, KeyedAccount};
use solana_sdk::instruction::{CompiledInstruction, InstructionError};
use solana_sdk::instruction_processor_utils;
use solana_sdk::message::Message;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::system_program;
use solana_sdk::transaction::TransactionError;
use std::collections::HashMap;
use std::sync::RwLock;
#[cfg(unix)]
use libloading::os::unix::*;
#[cfg(windows)]
use libloading::os::windows::*;
/// Return true if the slice has any duplicate elements
pub fn has_duplicates<T: PartialEq>(xs: &[T]) -> bool {
@ -75,8 +83,11 @@ fn verify_instruction(
pub type ProcessInstruction =
fn(&Pubkey, &mut [KeyedAccount], &[u8], u64) -> Result<(), InstructionError>;
pub type SymbolCache = RwLock<HashMap<Vec<u8>, Symbol<instruction_processor_utils::Entrypoint>>>;
pub struct MessageProcessor {
instruction_processors: Vec<(Pubkey, ProcessInstruction)>,
symbol_cache: SymbolCache,
}
impl Default for MessageProcessor {
@ -88,6 +99,7 @@ impl Default for MessageProcessor {
Self {
instruction_processors,
symbol_cache: RwLock::new(HashMap::new()),
}
}
}
@ -145,6 +157,7 @@ impl MessageProcessor {
&mut keyed_accounts,
&instruction.data,
tick_height,
&self.symbol_cache,
)
}