avoid data copies in writing to cache (#23674)
This commit is contained in:
committed by
GitHub
parent
29af42f428
commit
b5a99b9b09
@ -57,7 +57,7 @@ use {
|
|||||||
solana_measure::measure::Measure,
|
solana_measure::measure::Measure,
|
||||||
solana_rayon_threadlimit::get_thread_count,
|
solana_rayon_threadlimit::get_thread_count,
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount},
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
clock::{BankId, Epoch, Slot, SlotCount},
|
clock::{BankId, Epoch, Slot, SlotCount},
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
genesis_config::{ClusterType, GenesisConfig},
|
genesis_config::{ClusterType, GenesisConfig},
|
||||||
@ -566,6 +566,19 @@ impl<'a> ReadableAccount for LoadedAccount<'a> {
|
|||||||
LoadedAccount::Cached(cached_account) => cached_account.account.rent_epoch(),
|
LoadedAccount::Cached(cached_account) => cached_account.account.rent_epoch(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn to_account_shared_data(&self) -> AccountSharedData {
|
||||||
|
match self {
|
||||||
|
LoadedAccount::Stored(_stored_account_meta) => AccountSharedData::create(
|
||||||
|
self.lamports(),
|
||||||
|
self.data().to_vec(),
|
||||||
|
*self.owner(),
|
||||||
|
self.executable(),
|
||||||
|
self.rent_epoch(),
|
||||||
|
),
|
||||||
|
// clone here to prevent data copy
|
||||||
|
LoadedAccount::Cached(cached_account) => cached_account.account.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Default, Debug)]
|
||||||
|
@ -253,6 +253,10 @@ impl ReadableAccount for AccountSharedData {
|
|||||||
fn rent_epoch(&self) -> Epoch {
|
fn rent_epoch(&self) -> Epoch {
|
||||||
self.rent_epoch
|
self.rent_epoch
|
||||||
}
|
}
|
||||||
|
fn to_account_shared_data(&self) -> AccountSharedData {
|
||||||
|
// avoid data copy here
|
||||||
|
self.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadableAccount for Ref<'_, AccountSharedData> {
|
impl ReadableAccount for Ref<'_, AccountSharedData> {
|
||||||
@ -271,6 +275,16 @@ impl ReadableAccount for Ref<'_, AccountSharedData> {
|
|||||||
fn rent_epoch(&self) -> Epoch {
|
fn rent_epoch(&self) -> Epoch {
|
||||||
self.rent_epoch
|
self.rent_epoch
|
||||||
}
|
}
|
||||||
|
fn to_account_shared_data(&self) -> AccountSharedData {
|
||||||
|
AccountSharedData {
|
||||||
|
lamports: self.lamports(),
|
||||||
|
// avoid data copy here
|
||||||
|
data: Arc::clone(&self.data),
|
||||||
|
owner: *self.owner(),
|
||||||
|
executable: self.executable(),
|
||||||
|
rent_epoch: self.rent_epoch(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadableAccount for Ref<'_, Account> {
|
impl ReadableAccount for Ref<'_, Account> {
|
||||||
|
Reference in New Issue
Block a user