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

Commit 7756031

Browse files
arkpargavofyork
authored andcommitted
Caching optimizations (#2505)
1 parent 533af43 commit 7756031

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

ethcore/src/evm/interpreter/shared_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use util::sha3::*;
2121
use bit_set::BitSet;
2222
use super::super::instructions;
2323

24-
const CACHE_CODE_ITEMS: usize = 4096;
24+
const CACHE_CODE_ITEMS: usize = 65536;
2525

2626
/// GLobal cache for EVM interpreter
2727
pub struct SharedCache {

ethcore/src/state/mod.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ pub type ApplyResult = Result<ApplyOutcome, Error>;
4747
/// Account modification state. Used to check if the account was
4848
/// Modified in between commits and overall.
4949
enum AccountState {
50-
/// Account was never modified in this state object.
51-
Clean,
50+
/// Account was loaded from disk and never modified in this state object.
51+
CleanFresh,
52+
/// Account was loaded from the global cache and never modified.
53+
CleanCached,
5254
/// Account has been modified and is not committed to the trie yet.
53-
/// This is set than any of the account data is changed, including
55+
/// This is set if any of the account data is changed, including
5456
/// storage and code.
5557
Dirty,
5658
/// Account was modified and committed to the trie.
57-
Commited,
59+
Committed,
5860
}
5961

6062
#[derive(Debug)]
@@ -105,7 +107,15 @@ impl AccountEntry {
105107
fn new_clean(account: Option<Account>) -> AccountEntry {
106108
AccountEntry {
107109
account: account,
108-
state: AccountState::Clean,
110+
state: AccountState::CleanFresh,
111+
}
112+
}
113+
114+
// Create a new account entry and mark it as clean and cached.
115+
fn new_clean_cached(account: Option<Account>) -> AccountEntry {
116+
AccountEntry {
117+
account: account,
118+
state: AccountState::CleanCached,
109119
}
110120
}
111121

@@ -508,7 +518,7 @@ impl State {
508518
{
509519
let mut trie = factories.trie.from_existing(db.as_hashdb_mut(), root).unwrap();
510520
for (address, ref mut a) in accounts.iter_mut().filter(|&(_, ref a)| a.is_dirty()) {
511-
a.state = AccountState::Commited;
521+
a.state = AccountState::Committed;
512522
match a.account {
513523
Some(ref mut account) => {
514524
try!(trie.insert(address, &account.rlp()));
@@ -526,7 +536,7 @@ impl State {
526536
fn commit_cache(&mut self) {
527537
let mut addresses = self.cache.borrow_mut();
528538
trace!("Committing cache {:?} entries", addresses.len());
529-
for (address, a) in addresses.drain().filter(|&(_, ref a)| !a.is_dirty()) {
539+
for (address, a) in addresses.drain().filter(|&(_, ref a)| a.state == AccountState::Committed || a.state == AccountState::CleanFresh) {
530540
self.db.cache_account(address, a.account);
531541
}
532542
}
@@ -638,10 +648,7 @@ impl State {
638648
Self::update_account_cache(require, account, accountdb.as_hashdb());
639649
}
640650
let r = f(maybe_acc.as_ref());
641-
match maybe_acc {
642-
Some(account) => self.insert_cache(a, AccountEntry::new_clean(Some(account))),
643-
None => self.insert_cache(a, AccountEntry::new_clean(None)),
644-
}
651+
self.insert_cache(a, AccountEntry::new_clean(maybe_acc));
645652
r
646653
}
647654
}
@@ -660,8 +667,7 @@ impl State {
660667
let contains_key = self.cache.borrow().contains_key(a);
661668
if !contains_key {
662669
match self.db.get_cached_account(a) {
663-
Some(Some(acc)) => self.insert_cache(a, AccountEntry::new_clean(Some(acc))),
664-
Some(None) => self.insert_cache(a, AccountEntry::new_clean(None)),
670+
Some(acc) => self.insert_cache(a, AccountEntry::new_clean_cached(acc)),
665671
None => {
666672
let maybe_acc = if self.db.check_account_bloom(a) {
667673
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);

ethcore/src/state_db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use bloom_journal::{Bloom, BloomJournal};
2424
use db::COL_ACCOUNT_BLOOM;
2525
use byteorder::{LittleEndian, ByteOrder};
2626

27-
const STATE_CACHE_ITEMS: usize = 65536;
27+
const STATE_CACHE_ITEMS: usize = 256000;
2828

2929
pub const ACCOUNT_BLOOM_SPACE: usize = 1048576;
3030
pub const DEFAULT_ACCOUNT_PRESET: usize = 1000000;

0 commit comments

Comments
 (0)