Skip to content

Commit

Permalink
EVM-899: Skip write when no change (#709)
Browse files Browse the repository at this point in the history
* EVM-899: Don't even call the HAMT store if there was no change.

* EVM-899: Measurement updates with flush fix.
  • Loading branch information
aakoshh authored Oct 1, 2022
1 parent 856ca95 commit 4707c62
Show file tree
Hide file tree
Showing 15 changed files with 520 additions and 524 deletions.
36 changes: 16 additions & 20 deletions actors/evm/src/interpreter/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ impl<'r, BS: Blockstore, RT: Runtime<BS>> System<'r, BS, RT> {

/// Get value of a storage key.
pub fn get_storage(&mut self, key: U256) -> Result<Option<U256>, StatusCode> {
let mut key_bytes = [0u8; 32];
key.to_big_endian(&mut key_bytes);

Ok(self.state.get(&key).map_err(|e| StatusCode::InternalError(e.to_string()))?.cloned())
}

Expand All @@ -58,24 +55,23 @@ impl<'r, BS: Blockstore, RT: Runtime<BS>> System<'r, BS, RT> {
key: U256,
value: Option<U256>,
) -> Result<StorageStatus, StatusCode> {
let mut key_bytes = [0u8; 32];
key.to_big_endian(&mut key_bytes);

let prev_value =
self.state.get(&key).map_err(|e| StatusCode::InternalError(e.to_string()))?.cloned();
let prev_value = self.get_storage(key)?;

let mut storage_status =
if prev_value == value { StorageStatus::Unchanged } else { StorageStatus::Modified };

if value.is_none() {
self.state.delete(&key).map_err(|e| StatusCode::InternalError(e.to_string()))?;
storage_status = StorageStatus::Deleted;
} else {
self.state
.set(key, value.unwrap())
.map_err(|e| StatusCode::InternalError(e.to_string()))?;
match (prev_value, value) {
(None, None) => Ok(StorageStatus::Unchanged),
(Some(_), None) => {
self.state.delete(&key).map_err(|e| StatusCode::InternalError(e.to_string()))?;
Ok(StorageStatus::Deleted)
}
(Some(p), Some(n)) if p == n => Ok(StorageStatus::Unchanged),
(_, Some(v)) => {
self.state.set(key, v).map_err(|e| StatusCode::InternalError(e.to_string()))?;
if prev_value.is_none() {
Ok(StorageStatus::Added)
} else {
Ok(StorageStatus::Modified)
}
}
}

Ok(storage_status)
}
}
200 changes: 100 additions & 100 deletions actors/evm/tests/measurements/array_read_n1.jsonline

Large diffs are not rendered by default.

Binary file modified actors/evm/tests/measurements/array_read_n1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
200 changes: 100 additions & 100 deletions actors/evm/tests/measurements/array_read_n100.jsonline

Large diffs are not rendered by default.

Binary file modified actors/evm/tests/measurements/array_read_n100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions actors/evm/tests/measurements/mapping_add_n1.jsonline
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"i":0,"series":1,"stats":{"get_bytes":2185,"get_count":4,"put_bytes":2188,"put_count":5}}
{"i":0,"series":1,"stats":{"get_bytes":2185,"get_count":4,"put_bytes":2185,"put_count":4}}
{"i":1,"series":1,"stats":{"get_bytes":2185,"get_count":4,"put_bytes":180,"put_count":2}}
{"i":2,"series":1,"stats":{"get_bytes":2275,"get_count":4,"put_bytes":261,"put_count":2}}
{"i":3,"series":1,"stats":{"get_bytes":2356,"get_count":4,"put_bytes":345,"put_count":2}}
Expand Down Expand Up @@ -98,7 +98,7 @@
{"i":97,"series":1,"stats":{"get_bytes":9383,"get_count":4,"put_bytes":7362,"put_count":2}}
{"i":98,"series":1,"stats":{"get_bytes":9457,"get_count":4,"put_bytes":7437,"put_count":2}}
{"i":99,"series":1,"stats":{"get_bytes":9532,"get_count":4,"put_bytes":7511,"put_count":2}}
{"i":0,"series":2,"stats":{"get_bytes":9606,"get_count":4,"put_bytes":7511,"put_count":2}}
{"i":0,"series":2,"stats":{"get_bytes":9606,"get_count":4,"put_bytes":87,"put_count":1}}
{"i":1,"series":2,"stats":{"get_bytes":9606,"get_count":4,"put_bytes":7585,"put_count":2}}
{"i":2,"series":2,"stats":{"get_bytes":9680,"get_count":4,"put_bytes":7658,"put_count":2}}
{"i":3,"series":2,"stats":{"get_bytes":9753,"get_count":4,"put_bytes":7732,"put_count":2}}
Expand Down
Binary file modified actors/evm/tests/measurements/mapping_add_n1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions actors/evm/tests/measurements/mapping_add_n100.jsonline
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"i":0,"series":1,"stats":{"get_bytes":2185,"get_count":4,"put_bytes":2188,"put_count":5}}
{"i":0,"series":1,"stats":{"get_bytes":2185,"get_count":4,"put_bytes":2185,"put_count":4}}
{"i":1,"series":1,"stats":{"get_bytes":2185,"get_count":4,"put_bytes":7494,"put_count":2}}
{"i":2,"series":1,"stats":{"get_bytes":9589,"get_count":4,"put_bytes":15001,"put_count":4}}
{"i":3,"series":1,"stats":{"get_bytes":16765,"get_count":5,"put_bytes":22582,"put_count":11}}
Expand Down Expand Up @@ -98,7 +98,7 @@
{"i":97,"series":1,"stats":{"get_bytes":254250,"get_count":88,"put_bytes":259638,"put_count":86}}
{"i":98,"series":1,"stats":{"get_bytes":245365,"get_count":83,"put_bytes":250747,"put_count":81}}
{"i":99,"series":1,"stats":{"get_bytes":265670,"get_count":91,"put_bytes":271053,"put_count":89}}
{"i":0,"series":2,"stats":{"get_bytes":262559,"get_count":87,"put_bytes":11133,"put_count":2}}
{"i":0,"series":2,"stats":{"get_bytes":262559,"get_count":87,"put_bytes":87,"put_count":1}}
{"i":1,"series":2,"stats":{"get_bytes":256304,"get_count":86,"put_bytes":261594,"put_count":84}}
{"i":2,"series":2,"stats":{"get_bytes":259549,"get_count":88,"put_bytes":264832,"put_count":86}}
{"i":3,"series":2,"stats":{"get_bytes":258453,"get_count":87,"put_bytes":263745,"put_count":85}}
Expand Down
Binary file modified actors/evm/tests/measurements/mapping_add_n100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
200 changes: 100 additions & 100 deletions actors/evm/tests/measurements/mapping_overwrite.jsonline

Large diffs are not rendered by default.

Binary file modified actors/evm/tests/measurements/mapping_overwrite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4707c62

Please sign in to comment.