Some more optimizations by avoiding coping
This commit is contained in:
parent
e28a3101c9
commit
bc1c8c75ec
|
@ -65,9 +65,7 @@ impl AccountDataByCommitment {
|
|||
Commitment::Finalized => self.finalized_account.as_ref(),
|
||||
};
|
||||
|
||||
let Some(account_data) = account_data else {
|
||||
return None;
|
||||
};
|
||||
let account_data = account_data?;
|
||||
|
||||
// check size filter first before decompressing
|
||||
for filter in filters {
|
||||
|
|
|
@ -313,13 +313,13 @@ impl AccountStorageInterface for InmemoryAccountStore {
|
|||
|
||||
let mut return_vec = vec![];
|
||||
let store_read_lk = self.accounts_store.read().unwrap();
|
||||
let mut retry_list = BTreeSet::new();
|
||||
let mut retry_list = Vec::with_capacity(128);
|
||||
// optimization to avoid locking for each account
|
||||
for program_account_index in lk.read().unwrap().iter() {
|
||||
let lk_on_account = match store_read_lk[*program_account_index].try_read() {
|
||||
Ok(lk) => lk,
|
||||
Err(_) => {
|
||||
retry_list.insert(*program_account_index);
|
||||
retry_list.push(*program_account_index);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
@ -331,7 +331,6 @@ impl AccountStorageInterface for InmemoryAccountStore {
|
|||
&account_filters,
|
||||
);
|
||||
}
|
||||
|
||||
// retry for the accounts which were locked
|
||||
for retry_account_index in retry_list {
|
||||
let lk_on_account = store_read_lk[retry_account_index].read().unwrap();
|
||||
|
|
|
@ -34,15 +34,27 @@ impl MemcmpFilter {
|
|||
}
|
||||
|
||||
pub fn bytes_match(&self, data: &[u8]) -> bool {
|
||||
let bytes = self.bytes();
|
||||
let offset = self.offset as usize;
|
||||
if offset > data.len() {
|
||||
return false;
|
||||
// optimize for bytes / avoid copying
|
||||
if let MemcmpFilterData::Bytes(bytes) = &self.data {
|
||||
let offset = self.offset as usize;
|
||||
if offset > data.len() {
|
||||
return false;
|
||||
}
|
||||
if data[offset..].len() < bytes.len() {
|
||||
return false;
|
||||
}
|
||||
data[offset..offset + bytes.len()] == bytes[..]
|
||||
} else {
|
||||
let bytes = self.bytes();
|
||||
let offset = self.offset as usize;
|
||||
if offset > data.len() {
|
||||
return false;
|
||||
}
|
||||
if data[offset..].len() < bytes.len() {
|
||||
return false;
|
||||
}
|
||||
data[offset..offset + bytes.len()] == bytes[..]
|
||||
}
|
||||
if data[offset..].len() < bytes.len() {
|
||||
return false;
|
||||
}
|
||||
data[offset..offset + bytes.len()] == bytes[..]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
cargo +nightly-2023-10-05 fmt --all
|
||||
cargo +nightly-2023-10-05 clippy --locked --workspace --all-targets -- -D warnings
|
||||
cargo +1.78.0 fmt --all
|
||||
cargo +1.78.0 clippy --locked --workspace --all-targets -- -D warnings
|
Loading…
Reference in New Issue