State cache and other performance optimizations (#1345)

* State caching

* Better code caching

* Execution optimizaton

* More optimizations

* Updated wasmi

* Caching test

* Style

* Style

* Reverted some minor changes

* Style and typos

* Style and typos

* Removed panics on missing memory
This commit is contained in:
Arkadiy Paronyan
2019-01-08 15:13:13 +03:00
committed by Gav Wood
parent e0639c435b
commit b104c02eb6
26 changed files with 796 additions and 266 deletions
+7 -21
View File
@@ -65,9 +65,6 @@ pub use proving_backend::{create_proof_check_backend, create_proof_check_backend
pub use trie_backend_essence::{TrieBackendStorage, Storage};
pub use trie_backend::TrieBackend;
/// Default num of pages for the heap
const DEFAULT_HEAP_PAGES :u64 = 1024;
/// State Machine Error bound.
///
/// This should reflect WASM error type bound for future compatibility.
@@ -98,10 +95,15 @@ impl fmt::Display for ExecutionError {
/// Externalities: pinned to specific active address.
pub trait Externalities<H: Hasher> {
/// Read storage of current contract being called.
/// Read runtime storage.
fn storage(&self, key: &[u8]) -> Option<Vec<u8>>;
/// Read child storage of current contract being called.
/// Get storage value hash. This may be optimized for large values.
fn storage_hash(&self, key: &[u8]) -> Option<H::Out> {
self.storage(key).map(|v| H::hash(&v))
}
/// Read child runtime storage.
fn child_storage(&self, storage_key: &[u8], key: &[u8]) -> Option<Vec<u8>>;
/// Set storage entry `key` of current contract being called (effective immediately).
@@ -171,8 +173,6 @@ pub trait CodeExecutor<H: Hasher>: Sized + Send + Sync {
fn call<E: Externalities<H>>(
&self,
ext: &mut E,
heap_pages: usize,
code: &[u8],
method: &str,
data: &[u8],
use_native: bool
@@ -297,14 +297,6 @@ where
{
let strategy: ExecutionStrategy = (&manager).into();
// make a copy.
let code = try_read_overlay_value(overlay, backend, well_known_keys::CODE)?
.ok_or_else(|| Box::new(ExecutionError::CodeEntryDoesNotExist) as Box<Error>)?
.to_vec();
let heap_pages = try_read_overlay_value(overlay, backend, well_known_keys::HEAP_PAGES)?
.and_then(|v| u64::decode(&mut &v[..])).unwrap_or(DEFAULT_HEAP_PAGES) as usize;
// read changes trie configuration. The reason why we're doing it here instead of the
// `OverlayedChanges` constructor is that we need proofs for this read as a part of
// proof-of-execution on light clients. And the proof is recorded by the backend which
@@ -328,8 +320,6 @@ where
let mut externalities = ext::Ext::new(overlay, backend, changes_trie_storage);
let retval = exec.call(
&mut externalities,
heap_pages,
&code,
method,
call_data,
// attempt to run native first, if we're not directed to run wasm only
@@ -357,8 +347,6 @@ where
let mut externalities = ext::Ext::new(overlay, backend, changes_trie_storage);
let retval = exec.call(
&mut externalities,
heap_pages,
&code,
method,
call_data,
false,
@@ -614,8 +602,6 @@ mod tests {
fn call<E: Externalities<H>>(
&self,
ext: &mut E,
_heap_pages: usize,
_code: &[u8],
_method: &str,
_data: &[u8],
use_native: bool