Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

More caching optimizations #2505

Merged
merged 1 commit into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethcore/src/evm/interpreter/shared_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use util::sha3::*;
use bit_set::BitSet;
use super::super::instructions;

const CACHE_CODE_ITEMS: usize = 4096;
const CACHE_CODE_ITEMS: usize = 65536;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interim fix before this is made configurable.


/// GLobal cache for EVM interpreter
pub struct SharedCache {
Expand Down
32 changes: 19 additions & 13 deletions ethcore/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ pub type ApplyResult = Result<ApplyOutcome, Error>;
/// Account modification state. Used to check if the account was
/// Modified in between commits and overall.
enum AccountState {
/// Account was never modified in this state object.
Clean,
/// Account was loaded from disk and never modified in this state object.
CleanFresh,
/// Account was loaded from the global cache and never modified.
CleanCached,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tracks accounts that were loaded from the global cache to be modified, but modification was reverted with the snapshot. In such case they won't be passed back to the global cache.

/// Account has been modified and is not committed to the trie yet.
/// This is set than any of the account data is changed, including
/// This is set if any of the account data is changed, including
/// storage and code.
Dirty,
/// Account was modified and committed to the trie.
Commited,
Committed,
}

#[derive(Debug)]
Expand Down Expand Up @@ -105,7 +107,15 @@ impl AccountEntry {
fn new_clean(account: Option<Account>) -> AccountEntry {
AccountEntry {
account: account,
state: AccountState::Clean,
state: AccountState::CleanFresh,
}
}

// Create a new account entry and mark it as clean and cached.
fn new_clean_cached(account: Option<Account>) -> AccountEntry {
AccountEntry {
account: account,
state: AccountState::CleanCached,
}
}

Expand Down Expand Up @@ -508,7 +518,7 @@ impl State {
{
let mut trie = factories.trie.from_existing(db.as_hashdb_mut(), root).unwrap();
for (address, ref mut a) in accounts.iter_mut().filter(|&(_, ref a)| a.is_dirty()) {
a.state = AccountState::Commited;
a.state = AccountState::Committed;
match a.account {
Some(ref mut account) => {
try!(trie.insert(address, &account.rlp()));
Expand All @@ -526,7 +536,7 @@ impl State {
fn commit_cache(&mut self) {
let mut addresses = self.cache.borrow_mut();
trace!("Committing cache {:?} entries", addresses.len());
for (address, a) in addresses.drain().filter(|&(_, ref a)| !a.is_dirty()) {
for (address, a) in addresses.drain().filter(|&(_, ref a)| a.state == AccountState::Committed || a.state == AccountState::CleanFresh) {
self.db.cache_account(address, a.account);
}
}
Expand Down Expand Up @@ -638,10 +648,7 @@ impl State {
Self::update_account_cache(require, account, accountdb.as_hashdb());
}
let r = f(maybe_acc.as_ref());
match maybe_acc {
Some(account) => self.insert_cache(a, AccountEntry::new_clean(Some(account))),
None => self.insert_cache(a, AccountEntry::new_clean(None)),
}
self.insert_cache(a, AccountEntry::new_clean(maybe_acc));
r
}
}
Expand All @@ -660,8 +667,7 @@ impl State {
let contains_key = self.cache.borrow().contains_key(a);
if !contains_key {
match self.db.get_cached_account(a) {
Some(Some(acc)) => self.insert_cache(a, AccountEntry::new_clean(Some(acc))),
Some(None) => self.insert_cache(a, AccountEntry::new_clean(None)),
Some(acc) => self.insert_cache(a, AccountEntry::new_clean_cached(acc)),
None => {
let maybe_acc = if self.db.check_account_bloom(a) {
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use bloom_journal::{Bloom, BloomJournal};
use db::COL_ACCOUNT_BLOOM;
use byteorder::{LittleEndian, ByteOrder};

const STATE_CACHE_ITEMS: usize = 65536;
const STATE_CACHE_ITEMS: usize = 256000;

pub const ACCOUNT_BLOOM_SPACE: usize = 1048576;
pub const DEFAULT_ACCOUNT_PRESET: usize = 1000000;
Expand Down